#include <ctype.h>
#include <limits>

#include <wx/tokenzr.h>
#include <wx/mstream.h>
#include <wx/image.h>
#if wxUSE_FFILE
#include <wx/ffile.h>
#elif wxUSE_FILE
#include <wx/file.h>
#endif
#include <wx/log.h>
#include <wx/textctrl.h>
#include <wx/dcclient.h>
#include <wx/dcbuffer.h>

#include "ScintillaWX.h"
#include "wx/wxscintilla.h"

#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif

const wxChar* wxSCINameStr = _T( "SCIwindow" );

#ifdef MAKELONG
#undef MAKELONG
#endif

#define MAKELONG(a, b) ((a) | ((b) << 16))

static long wxColourAsLong( const wxColour& co ) {
  return ( ( ( long )co.Blue()  << 16 ) | ( ( long )co.Green() <<  8 ) | ( ( long )co.Red() ) );
}

static wxColour wxColourFromLong( long c ) {
  wxColour clr;
  clr.Set( ( unsigned char )( c & 0xff ), ( unsigned char )( ( c >> 8 ) & 0xff ), ( unsigned char )( ( c >> 16 ) & 0xff ) );
  return clr;
}


static wxColour wxColourFromSpec( const wxString& spec ) {
  if( spec.GetChar( 0 ) == _T( '#' ) ) {
    long red, green, blue;
    red = green = blue = 0;
    spec.Mid( 1, 2 ).ToLong( &red, 16 );
    spec.Mid( 3, 2 ).ToLong( &green, 16 );
    spec.Mid( 5, 2 ).ToLong( &blue, 16 );
    return wxColour( ( unsigned char )red, ( unsigned char )green, ( unsigned char )blue );
  } else {
    return wxColour( spec );
  }
}


DEFINE_EVENT_TYPE( wxEVT_SCI_CHANGE )
DEFINE_EVENT_TYPE( wxEVT_SCI_STYLENEEDED )
DEFINE_EVENT_TYPE( wxEVT_SCI_CHARADDED )
DEFINE_EVENT_TYPE( wxEVT_SCI_SAVEPOINTREACHED )
DEFINE_EVENT_TYPE( wxEVT_SCI_SAVEPOINTLEFT )
DEFINE_EVENT_TYPE( wxEVT_SCI_ROMODIFYATTEMPT )
DEFINE_EVENT_TYPE( wxEVT_SCI_KEY )
DEFINE_EVENT_TYPE( wxEVT_SCI_DOUBLECLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_UPDATEUI )
DEFINE_EVENT_TYPE( wxEVT_SCI_MODIFIED )
DEFINE_EVENT_TYPE( wxEVT_SCI_MACRORECORD )
DEFINE_EVENT_TYPE( wxEVT_SCI_MARGINCLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_NEEDSHOWN )
DEFINE_EVENT_TYPE( wxEVT_SCI_PAINTED )
DEFINE_EVENT_TYPE( wxEVT_SCI_USERLISTSELECTION )
DEFINE_EVENT_TYPE( wxEVT_SCI_URIDROPPED )
DEFINE_EVENT_TYPE( wxEVT_SCI_DWELLSTART )
DEFINE_EVENT_TYPE( wxEVT_SCI_DWELLEND )
DEFINE_EVENT_TYPE( wxEVT_SCI_START_DRAG )
DEFINE_EVENT_TYPE( wxEVT_SCI_FINISHED_DRAG )
DEFINE_EVENT_TYPE( wxEVT_SCI_DRAG_OVER )
DEFINE_EVENT_TYPE( wxEVT_SCI_DO_DROP )
DEFINE_EVENT_TYPE( wxEVT_SCI_ZOOM )
DEFINE_EVENT_TYPE( wxEVT_SCI_HOTSPOT_CLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_HOTSPOT_DCLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_CALLTIP_CLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_AUTOCOMP_SELECTION )
DEFINE_EVENT_TYPE( wxEVT_SCI_INDICATOR_CLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_INDICATOR_RELEASE )
DEFINE_EVENT_TYPE( wxEVT_SCI_AUTOCOMP_CANCELLED )
DEFINE_EVENT_TYPE( wxEVT_SCI_AUTOCOMP_CHAR_DELETED )
DEFINE_EVENT_TYPE( wxEVT_SCI_HOTSPOT_RELEASE_CLICK )
DEFINE_EVENT_TYPE( wxEVT_SCI_CLIPBOARD_COPY )
DEFINE_EVENT_TYPE( wxEVT_SCI_CLIPBOARD_PASTE )
DEFINE_EVENT_TYPE( wxEVT_SCI_SETFOCUS )
DEFINE_EVENT_TYPE( wxEVT_SCI_KILLFOCUS )
DEFINE_EVENT_TYPE( wxEVT_SCI_TAB )
DEFINE_EVENT_TYPE( wxEVT_SCI_ESC )

BEGIN_EVENT_TABLE( wxScintilla, wxControl )
  EVT_PAINT( wxScintilla::OnPaint )
  EVT_SCROLLWIN( wxScintilla::OnScrollWin )
  EVT_SCROLL( wxScintilla::OnScroll )
  EVT_SIZE( wxScintilla::OnSize )
  EVT_LEFT_DOWN( wxScintilla::OnMouseLeftDown )
  EVT_LEFT_DCLICK( wxScintilla::OnMouseLeftDown )
  EVT_MOTION( wxScintilla::OnMouseMove )
  EVT_LEFT_UP( wxScintilla::OnMouseLeftUp )
  EVT_RIGHT_UP( wxScintilla::OnMouseRightUp )
  EVT_MOUSEWHEEL( wxScintilla::OnMouseWheel )
  EVT_MIDDLE_UP( wxScintilla::OnMouseMiddleUp )
  EVT_CHAR( wxScintilla::OnChar )
  EVT_KEY_DOWN( wxScintilla::OnKeyDown )
  EVT_KILL_FOCUS( wxScintilla::OnLoseFocus )
  EVT_SET_FOCUS( wxScintilla::OnGainFocus )
  EVT_SYS_COLOUR_CHANGED( wxScintilla::OnSysColourChanged )
  EVT_ERASE_BACKGROUND( wxScintilla::OnEraseBackground )
  EVT_MENU_RANGE( 10, 16, wxScintilla::OnMenu )
  EVT_LISTBOX_DCLICK( wxID_ANY, wxScintilla::OnListBox )
END_EVENT_TABLE()

IMPLEMENT_CLASS( wxScintilla, wxControl )
IMPLEMENT_DYNAMIC_CLASS( wxScintillaEvent, wxCommandEvent )

wxScintilla::wxScintilla( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
  m_swx = NULL;
  Create( parent, id, pos, size, style, name );
}


bool wxScintilla::Create( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
  if( !wxControl::Create( parent, id, pos, size, style | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name ) ) {
    wxSafeShowMessage( _T( "wxScintilla" ), _T( "Could not create a new wxControl instance." ) );
    return false;
  }
  #ifdef LINK_LEXERS
  Scintilla_LinkLexers();
  #endif
  m_swx = new ScintillaWX( this );
  if( !m_swx ) {
    wxSafeShowMessage( _T( "wxScintilla" ), _T( "Could not create a new ScintillaWX instance." ) );
  }
  m_stopWatch.Start();
  m_lastKeyDownConsumed = false;
  m_vScrollBar = NULL;
  m_hScrollBar = NULL;
  SetCodePage( wxSCI_CP_UTF8 );
  SetInitialSize( size );
  SetBackgroundStyle( wxBG_STYLE_CUSTOM );
  return true;
}


wxScintilla::~wxScintilla() {
  delete m_swx;
  m_swx = 0;
}




wxIntPtr wxScintilla::SendMsg( unsigned int msg, wxUIntPtr wp, wxIntPtr lp ) const

{
  return m_swx->WndProc( msg, wp, lp );
}


void wxScintilla::SetVScrollBar( wxScrollBar* bar ) {
  m_vScrollBar = bar;
  if( bar != NULL ) {
    SetScrollbar( wxVERTICAL, 0, 0, 0 );
  }
}


void wxScintilla::SetHScrollBar( wxScrollBar* bar ) {
  m_hScrollBar = bar;
  if( bar != NULL ) {
    SetScrollbar( wxHORIZONTAL, 0, 0, 0 );
  }
}




void wxScintilla::AddText( const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  SendMsg( SCI_ADDTEXT, strlen( buf ), ( uptr_t )( const char* )wx2sci( text ) );
}


void wxScintilla::AddText( const int length, const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  SendMsg( SCI_ADDTEXT, length, ( uptr_t )( const char* )buf );
}


void wxScintilla::AddStyledText( const wxMemoryBuffer& data ) {
  SendMsg( SCI_ADDSTYLEDTEXT, data.GetDataLen(), ( uptr_t )data.GetData() );
}

void wxScintilla::InsertText( int pos, const wxString& text ) {
  SendMsg( SCI_INSERTTEXT, pos, ( uptr_t )( const char* )wx2sci( text ) );
}

void wxScintilla::ChangeInsertion( int length, const wxString& text ) {
  SendMsg( SCI_CHANGEINSERTION, length, ( uptr_t )( const char* )wx2sci( text ) );
}

void wxScintilla::ClearAll() {
  SendMsg( SCI_CLEARALL, 0, 0 );
}

void wxScintilla::DeleteRange( int pos, int deleteLength ) {
  SendMsg( SCI_DELETERANGE, pos, deleteLength );
}

void wxScintilla::ClearDocumentStyle() {
  SendMsg( SCI_CLEARDOCUMENTSTYLE, 0, 0 );
}


int wxScintilla::GetLength() const {
  return SendMsg( SCI_GETLENGTH, 0, 0 );
}


int wxScintilla::GetCharAt( int pos ) const {
  return ( unsigned char )SendMsg( SCI_GETCHARAT, pos, 0 );
}


int wxScintilla::GetCurrentPos() const {
  return SendMsg( SCI_GETCURRENTPOS, 0, 0 );
}


int wxScintilla::GetAnchor() const {
  return SendMsg( SCI_GETANCHOR, 0, 0 );
}


int wxScintilla::GetStyleAt( int pos ) const {
  return ( unsigned char )SendMsg( SCI_GETSTYLEAT, pos, 0 );
}

void wxScintilla::Redo() {
  SendMsg( SCI_REDO, 0, 0 );
}


void wxScintilla::SetUndoCollection( bool collectUndo ) {
  SendMsg( SCI_SETUNDOCOLLECTION, collectUndo, 0 );
}



void wxScintilla::SetChangeCollection( bool collectChange ) {
  SendMsg( SCI_SETCHANGECOLLECTION, collectChange, 0 );
}


int wxScintilla::FindChangedLine( const int fromLine, const int toLine ) const {
  return SendMsg( SCI_GETCHANGEDLINE, fromLine, toLine );
}


void wxScintilla::SelectAll() {
  SendMsg( SCI_SELECTALL, 0, 0 );
}


void wxScintilla::SetSavePoint() {
  SendMsg( SCI_SETSAVEPOINT, 0, 0 );
}


wxMemoryBuffer wxScintilla::GetStyledText( int startPos, int endPos ) {
  wxMemoryBuffer buf;
  if( endPos < startPos ) {
    int temp = startPos;
    startPos = endPos;
    endPos = temp;
  }
  int len = endPos - startPos;
  if( !len ) {
    return buf;
  }
  TextRange tr;
  tr.lpstrText = ( char* )buf.GetWriteBuf( len * 2 + 1 );
  tr.chrg.cpMin = startPos;
  tr.chrg.cpMax = endPos;
  len = SendMsg( SCI_GETSTYLEDTEXT, 0, ( uptr_t )&tr );
  buf.UngetWriteBuf( len );
  return buf;
}


bool wxScintilla::CanRedo() const {
  return SendMsg( SCI_CANREDO, 0, 0 ) != 0;
}


int wxScintilla::MarkerLineFromHandle( int handle ) {
  return SendMsg( SCI_MARKERLINEFROMHANDLE, handle, 0 );
}

void wxScintilla::MarkerDeleteHandle( int handle ) {
  SendMsg( SCI_MARKERDELETEHANDLE, handle, 0 );
}


bool wxScintilla::GetUndoCollection() const {
  return SendMsg( SCI_GETUNDOCOLLECTION, 0, 0 ) != 0;
}


int wxScintilla::GetViewWhiteSpace() const {
  return SendMsg( SCI_GETVIEWWS, 0, 0 );
}

void wxScintilla::SetViewWhiteSpace( int viewWS ) {
  SendMsg( SCI_SETVIEWWS, viewWS, 0 );
}


int wxScintilla::PositionFromPoint( wxPoint pt ) const {
  return SendMsg( SCI_POSITIONFROMPOINT, pt.x, pt.y );
}


int wxScintilla::PositionFromPointClose( int x, int y ) {
  return SendMsg( SCI_POSITIONFROMPOINTCLOSE, x, y );
}

void wxScintilla::GotoLine( int line ) {
  SendMsg( SCI_GOTOLINE, line, 0 );
}

void wxScintilla::GotoPos( int pos ) {
  SendMsg( SCI_GOTOPOS, pos, 0 );
}


void wxScintilla::SetAnchor( int posAnchor ) {
  SendMsg( SCI_SETANCHOR, posAnchor, 0 );
}


wxString wxScintilla::GetCurLine( int* linePos ) {
  int len = LineLength( GetCurrentLine() );
  if( !len ) {
    if( linePos ) {
      *linePos = 0;
    }
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  int pos = SendMsg( SCI_GETCURLINE, len + 1, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  if( linePos ) {
    *linePos = pos;
  }
  return sci2wx( buf );
}


int wxScintilla::GetEndStyled() const {
  return SendMsg( SCI_GETENDSTYLED, 0, 0 );
}

void wxScintilla::ConvertEOLs( int eolMode ) {
  SendMsg( SCI_CONVERTEOLS, eolMode, 0 );
}


int wxScintilla::GetEOLMode() const {
  return SendMsg( SCI_GETEOLMODE, 0, 0 );
}

void wxScintilla::SetEOLMode( int eolMode ) {
  SendMsg( SCI_SETEOLMODE, eolMode, 0 );
}


void wxScintilla::StartStyling( int pos, int mask ) {
  SendMsg( SCI_STARTSTYLING, pos, mask );
}


void wxScintilla::SetStyling( int length, int style ) {
  SendMsg( SCI_SETSTYLING, length, style );
}


bool wxScintilla::GetBufferedDraw() const {
  return SendMsg( SCI_GETBUFFEREDDRAW, 0, 0 ) != 0;
}


void wxScintilla::SetBufferedDraw( bool buffered ) {
  SendMsg( SCI_SETBUFFEREDDRAW, buffered, 0 );
}

void wxScintilla::SetTabWidth( int tabWidth ) {
  SendMsg( SCI_SETTABWIDTH, tabWidth, 0 );
}


int wxScintilla::GetTabWidth() const {
  return SendMsg( SCI_GETTABWIDTH, 0, 0 );
}

void wxScintilla::ClearTabStops( int line ) {
  SendMsg( SCI_CLEARTABSTOPS, line, 0 );
}

void wxScintilla::AddTabStop( int line, int x ) {
  SendMsg( SCI_ADDTABSTOP, line, x );
}


int wxScintilla::GetNextTabStop( int line, int x ) {
  return SendMsg( SCI_GETNEXTTABSTOP, line, x );
}

void wxScintilla::SetCodePage( int codePage ) {
  wxASSERT_MSG( codePage == wxSCI_CP_UTF8,
                _T( "Only wxSCI_CP_UTF8 may be used when wxUSE_UNICODE is on." ) );
  SendMsg( SCI_SETCODEPAGE, codePage );
}


int wxScintilla::GetIMEInteraction() const {
  return SendMsg( SCI_GETIMEINTERACTION, 0, 0 );
}

void wxScintilla::SetIMEInteraction( int imeInteraction ) {
  SendMsg( SCI_SETIMEINTERACTION, imeInteraction, 0 );
}


void wxScintilla::MarkerDefine( int markerNumber, int markerSymbol,
                                const wxColour& foreground,
                                const wxColour& background ) {
  SendMsg( SCI_MARKERDEFINE, markerNumber, markerSymbol );
  if( foreground.IsOk() ) {
    MarkerSetForeground( markerNumber, foreground );
  }
  if( background.IsOk() ) {
    MarkerSetBackground( markerNumber, background );
  }
}

void wxScintilla::MarkerSetForeground( int markerNumber, const wxColour& fore ) {
  SendMsg( SCI_MARKERSETFORE, markerNumber, wxColourAsLong( fore ) );
}

void wxScintilla::MarkerSetBackground( int markerNumber, const wxColour& back ) {
  SendMsg( SCI_MARKERSETBACK, markerNumber, wxColourAsLong( back ) );
}

void wxScintilla::MarkerSetBackgroundSelected( int markerNumber, const wxColour& back ) {
  SendMsg( SCI_MARKERSETBACKSELECTED, markerNumber, wxColourAsLong( back ) );
}

void wxScintilla::MarkerEnableHighlight( bool enabled ) {
  SendMsg( SCI_MARKERENABLEHIGHLIGHT, enabled, 0 );
}


int wxScintilla::MarkerAdd( int line, int markerNumber ) {
  return SendMsg( SCI_MARKERADD, line, markerNumber );
}

void wxScintilla::MarkerDelete( int line, int markerNumber ) {
  SendMsg( SCI_MARKERDELETE, line, markerNumber );
}

void wxScintilla::MarkerDeleteAll( int markerNumber ) {
  SendMsg( SCI_MARKERDELETEALL, markerNumber, 0 );
}


int wxScintilla::MarkerGet( int line ) {
  return SendMsg( SCI_MARKERGET, line, 0 );
}


int wxScintilla::MarkerNext( int lineStart, int markerMask ) {
  return SendMsg( SCI_MARKERNEXT, lineStart, markerMask );
}


int wxScintilla::MarkerPrevious( int lineStart, int markerMask ) {
  return SendMsg( SCI_MARKERPREVIOUS, lineStart, markerMask );
}

void wxScintilla::MarkerDefineBitmap( int markerNumber, const wxBitmap& bmp ) {
  wxMemoryOutputStream strm;
  wxImage img = bmp.ConvertToImage();
  if( img.HasAlpha() ) {
    img.ConvertAlphaToMask();
  }
  img.SaveFile( strm, wxBITMAP_TYPE_XPM );
  size_t len = strm.GetSize();
  char* buff = new char[len + 1];
  strm.CopyTo( buff, len );
  buff[len] = 0;
  SendMsg( SCI_MARKERDEFINEPIXMAP, markerNumber, ( uptr_t )buff );
  delete [] buff;
}

void wxScintilla::MarkerAddSet( int line, int set ) {
  SendMsg( SCI_MARKERADDSET, line, set );
}

void wxScintilla::MarkerSetAlpha( int markerNumber, int alpha ) {
  SendMsg( SCI_MARKERSETALPHA, markerNumber, alpha );
}

void wxScintilla::SetMarginType( int margin, int marginType ) {
  SendMsg( SCI_SETMARGINTYPEN, margin, marginType );
}


int wxScintilla::GetMarginType( int margin ) const {
  return SendMsg( SCI_GETMARGINTYPEN, margin, 0 );
}

void wxScintilla::SetMarginWidth( int margin, int pixelWidth ) {
  SendMsg( SCI_SETMARGINWIDTHN, margin, pixelWidth );
}


int wxScintilla::GetMarginWidth( int margin ) const {
  return SendMsg( SCI_GETMARGINWIDTHN, margin, 0 );
}

void wxScintilla::SetMarginMask( int margin, int mask ) {
  SendMsg( SCI_SETMARGINMASKN, margin, mask );
}


int wxScintilla::GetMarginMask( int margin ) const {
  return SendMsg( SCI_GETMARGINMASKN, margin, 0 );
}

void wxScintilla::SetMarginSensitive( int margin, bool sensitive ) {
  SendMsg( SCI_SETMARGINSENSITIVEN, margin, sensitive );
}


bool wxScintilla::GetMarginSensitive( int margin ) const {
  return SendMsg( SCI_GETMARGINSENSITIVEN, margin, 0 ) != 0;
}

void wxScintilla::SetMarginCursor( int margin, int cursor ) {
  SendMsg( SCI_SETMARGINCURSORN, margin, cursor );
}


int wxScintilla::GetMarginCursor( int margin ) const {
  return SendMsg( SCI_GETMARGINCURSORN, margin, 0 );
}

void wxScintilla::StyleClearAll() {
  SendMsg( SCI_STYLECLEARALL, 0, 0 );
}

void wxScintilla::StyleSetForeground( int style, const wxColour& fore ) {
  SendMsg( SCI_STYLESETFORE, style, wxColourAsLong( fore ) );
}

void wxScintilla::StyleSetBackground( int style, const wxColour& back ) {
  SendMsg( SCI_STYLESETBACK, style, wxColourAsLong( back ) );
}

void wxScintilla::StyleSetBold( int style, bool bold ) {
  SendMsg( SCI_STYLESETBOLD, style, bold );
}

void wxScintilla::StyleSetItalic( int style, bool italic ) {
  SendMsg( SCI_STYLESETITALIC, style, italic );
}

void wxScintilla::StyleSetSize( int style, int sizePoints ) {
  SendMsg( SCI_STYLESETSIZE, style, sizePoints );
}

void wxScintilla::StyleSetFaceName( int style, const wxString& fontName ) {
  SendMsg( SCI_STYLESETFONT, style, ( uptr_t )( const char* )wx2sci( fontName ) );
}

void wxScintilla::StyleSetEOLFilled( int style, bool filled ) {
  SendMsg( SCI_STYLESETEOLFILLED, style, filled );
}

void wxScintilla::StyleResetDefault() {
  SendMsg( SCI_STYLERESETDEFAULT, 0, 0 );
}

void wxScintilla::StyleSetUnderline( int style, bool underline ) {
  SendMsg( SCI_STYLESETUNDERLINE, style, underline );
}


wxColour wxScintilla::StyleGetForeground( int style ) const {
  long c = SendMsg( SCI_STYLEGETFORE, style, 0 );
  return wxColourFromLong( c );
}


wxColour wxScintilla::StyleGetBackground( int style ) const {
  long c = SendMsg( SCI_STYLEGETBACK, style, 0 );
  return wxColourFromLong( c );
}


bool wxScintilla::StyleGetBold( int style ) const {
  return SendMsg( SCI_STYLEGETBOLD, style, 0 ) != 0;
}


bool wxScintilla::StyleGetItalic( int style ) const {
  return SendMsg( SCI_STYLEGETITALIC, style, 0 ) != 0;
}


int wxScintilla::StyleGetSize( int style ) const {
  return SendMsg( SCI_STYLEGETSIZE, style, 0 );
}


wxString wxScintilla::StyleGetFaceName( int style ) {
  const int msg = SCI_STYLEGETFONT;
  const long len = SendMsg( msg, style, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, style, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


bool wxScintilla::StyleGetEOLFilled( int style ) const {
  return SendMsg( SCI_STYLEGETEOLFILLED, style, 0 ) != 0;
}


bool wxScintilla::StyleGetUnderline( int style ) const {
  return SendMsg( SCI_STYLEGETUNDERLINE, style, 0 ) != 0;
}


int wxScintilla::StyleGetCase( int style ) const {
  return SendMsg( SCI_STYLEGETCASE, style, 0 );
}


int wxScintilla::StyleGetCharacterSet( int style ) const {
  return SendMsg( SCI_STYLEGETCHARACTERSET, style, 0 );
}


bool wxScintilla::StyleGetVisible( int style ) const {
  return SendMsg( SCI_STYLEGETVISIBLE, style, 0 ) != 0;
}


bool wxScintilla::StyleGetChangeable( int style ) const {
  return SendMsg( SCI_STYLEGETCHANGEABLE, style, 0 ) != 0;
}


bool wxScintilla::StyleGetHotSpot( int style ) const {
  return SendMsg( SCI_STYLEGETHOTSPOT, style, 0 ) != 0;
}

void wxScintilla::StyleSetCase( int style, int caseForce ) {
  SendMsg( SCI_STYLESETCASE, style, caseForce );
}

void wxScintilla::StyleSetSizeFractional( int style, int caseForce ) {
  SendMsg( SCI_STYLESETSIZEFRACTIONAL, style, caseForce );
}


int wxScintilla::StyleGetSizeFractional( int style ) const {
  return SendMsg( SCI_STYLEGETSIZEFRACTIONAL, style, 0 );
}

void wxScintilla::StyleSetWeight( int style, int weight ) {
  SendMsg( SCI_STYLESETWEIGHT, style, weight );
}


int wxScintilla::StyleGetWeight( int style ) const {
  return SendMsg( SCI_STYLEGETWEIGHT, style, 0 );
}

void wxScintilla::StyleSetHotSpot( int style, bool hotspot ) {
  SendMsg( SCI_STYLESETHOTSPOT, style, hotspot );
}

void wxScintilla::SetSelForeground( bool useSetting, const wxColour& fore ) {
  SendMsg( SCI_SETSELFORE, useSetting, wxColourAsLong( fore ) );
}

void wxScintilla::SetSelBackground( bool useSetting, const wxColour& back ) {
  SendMsg( SCI_SETSELBACK, useSetting, wxColourAsLong( back ) );
}


int wxScintilla::GetSelAlpha() const {
  return SendMsg( SCI_GETSELALPHA, 0, 0 );
}

void wxScintilla::SetSelAlpha( int alpha ) {
  SendMsg( SCI_SETSELALPHA, alpha, 0 );
}


bool wxScintilla::GetSelEOLFilled() const {
  return SendMsg( SCI_GETSELEOLFILLED, 0, 0 ) != 0;
}

void wxScintilla::SetSelEOLFilled( bool filled ) {
  SendMsg( SCI_SETSELEOLFILLED, filled, 0 );
}

void wxScintilla::SetCaretForeground( const wxColour& fore ) {
  SendMsg( SCI_SETCARETFORE, wxColourAsLong( fore ), 0 );
}

void wxScintilla::CmdKeyAssign( int key, int modifiers, int cmd ) {
  SendMsg( SCI_ASSIGNCMDKEY, MAKELONG( key, modifiers ), cmd );
}

void wxScintilla::CmdKeyClear( int key, int modifiers ) {
  SendMsg( SCI_CLEARCMDKEY, MAKELONG( key, modifiers ) );
}

void wxScintilla::CmdKeyClearAll() {
  SendMsg( SCI_CLEARALLCMDKEYS, 0, 0 );
}

void wxScintilla::SetStyleBytes( int length, char* styleBytes ) {
  SendMsg( SCI_SETSTYLINGEX, length, ( uptr_t )styleBytes );
}

void wxScintilla::StyleSetVisible( int style, bool visible ) {
  SendMsg( SCI_STYLESETVISIBLE, style, visible );
}


int wxScintilla::GetCaretPeriod() const {
  return SendMsg( SCI_GETCARETPERIOD, 0, 0 );
}

void wxScintilla::SetCaretPeriod( int periodMilliseconds ) {
  SendMsg( SCI_SETCARETPERIOD, periodMilliseconds, 0 );
}


void wxScintilla::SetWordChars( const wxString& characters ) {
  SendMsg( SCI_SETWORDCHARS, 0, ( uptr_t )( const char* )wx2sci( characters ) );
}


wxString wxScintilla::GetWordChars() const {
  const int msg = SCI_GETWORDCHARS;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


void wxScintilla::BeginUndoAction() {
  SendMsg( SCI_BEGINUNDOACTION, 0, 0 );
}

void wxScintilla::EndUndoAction() {
  SendMsg( SCI_ENDUNDOACTION, 0, 0 );
}

void wxScintilla::IndicatorSetStyle( int indic, int style ) {
  SendMsg( SCI_INDICSETSTYLE, indic, style );
}


int wxScintilla::IndicatorGetStyle( int indic ) const {
  return SendMsg( SCI_INDICGETSTYLE, indic, 0 );
}

void wxScintilla::IndicatorSetForeground( int indic, const wxColour& fore ) {
  SendMsg( SCI_INDICSETFORE, indic, wxColourAsLong( fore ) );
}


wxColour wxScintilla::IndicatorGetForeground( int indic ) const {
  long c = SendMsg( SCI_INDICGETFORE, indic, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::IndicatorSetUnder( int indic, bool under ) {
  SendMsg( SCI_INDICSETUNDER, indic, under );
}


bool wxScintilla::IndicatorGetUnder( int indic ) const {
  return SendMsg( SCI_INDICGETUNDER, indic, 0 ) != 0;
}

void wxScintilla::SetWhitespaceForeground( bool useSetting, const wxColour& fore ) {
  SendMsg( SCI_SETWHITESPACEFORE, useSetting, wxColourAsLong( fore ) );
}

void wxScintilla::SetWhitespaceBackground( bool useSetting, const wxColour& back ) {
  SendMsg( SCI_SETWHITESPACEBACK, useSetting, wxColourAsLong( back ) );
}

void wxScintilla::SetWhitespaceSize( int size ) {
  SendMsg( SCI_SETWHITESPACESIZE, size, 0 );
}


int wxScintilla::GetWhitespaceSize() const {
  return SendMsg( SCI_GETWHITESPACESIZE, 0, 0 );
}


void wxScintilla::SetStyleBits( int bits ) {
  SendMsg( SCI_SETSTYLEBITS, bits, 0 );
}


int wxScintilla::GetStyleBits() const {
  return SendMsg( SCI_GETSTYLEBITS, 0, 0 );
}

void wxScintilla::SetLineState( int line, int state ) {
  SendMsg( SCI_SETLINESTATE, line, state );
}


int wxScintilla::GetLineState( int line ) const {
  return SendMsg( SCI_GETLINESTATE, line, 0 );
}


int wxScintilla::GetMaxLineState() const {
  return SendMsg( SCI_GETMAXLINESTATE, 0, 0 );
}


bool wxScintilla::GetCaretLineVisible() const {
  return SendMsg( SCI_GETCARETLINEVISIBLE, 0, 0 ) != 0;
}

void wxScintilla::SetCaretLineVisible( bool show ) {
  SendMsg( SCI_SETCARETLINEVISIBLE, show, 0 );
}


wxColour wxScintilla::GetCaretLineBackground() const {
  long c = SendMsg( SCI_GETCARETLINEBACK, 0, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::SetCaretLineBackground( const wxColour& back ) {
  SendMsg( SCI_SETCARETLINEBACK, wxColourAsLong( back ), 0 );
}


void wxScintilla::StyleSetChangeable( int style, bool changeable ) {
  SendMsg( SCI_STYLESETCHANGEABLE, style, changeable );
}


void wxScintilla::AutoCompShow( int lenEntered, const wxString& itemList ) {
  SendMsg( SCI_AUTOCSHOW, lenEntered, ( uptr_t )( const char* )wx2sci( itemList ) );
}

void wxScintilla::AutoCompCancel() {
  SendMsg( SCI_AUTOCCANCEL, 0, 0 );
}


bool wxScintilla::AutoCompActive() {
  return SendMsg( SCI_AUTOCACTIVE, 0, 0 ) != 0;
}


int wxScintilla::AutoCompPosStart() {
  return SendMsg( SCI_AUTOCPOSSTART, 0, 0 );
}

void wxScintilla::AutoCompComplete() {
  SendMsg( SCI_AUTOCCOMPLETE, 0, 0 );
}

void wxScintilla::AutoCompStops( const wxString& characterSet ) {
  SendMsg( SCI_AUTOCSTOPS, 0, ( uptr_t )( const char* )wx2sci( characterSet ) );
}


void wxScintilla::AutoCompSetSeparator( int separatorCharacter ) {
  SendMsg( SCI_AUTOCSETSEPARATOR, separatorCharacter, 0 );
}


int wxScintilla::AutoCompGetSeparator() const {
  return SendMsg( SCI_AUTOCGETSEPARATOR, 0, 0 );
}

void wxScintilla::AutoCompSelect( const wxString& text ) {
  SendMsg( SCI_AUTOCSELECT, 0, ( uptr_t )( const char* )wx2sci( text ) );
}


void wxScintilla::AutoCompSetCancelAtStart( bool cancel ) {
  SendMsg( SCI_AUTOCSETCANCELATSTART, cancel, 0 );
}


bool wxScintilla::AutoCompGetCancelAtStart() const {
  return SendMsg( SCI_AUTOCGETCANCELATSTART, 0, 0 ) != 0;
}


void wxScintilla::AutoCompSetFillUps( const wxString& characterSet ) {
  SendMsg( SCI_AUTOCSETFILLUPS, 0, ( uptr_t )( const char* )wx2sci( characterSet ) );
}

void wxScintilla::AutoCompSetChooseSingle( bool chooseSingle ) {
  SendMsg( SCI_AUTOCSETCHOOSESINGLE, chooseSingle, 0 );
}


bool wxScintilla::AutoCompGetChooseSingle() const {
  return SendMsg( SCI_AUTOCGETCHOOSESINGLE, 0, 0 ) != 0;
}

void wxScintilla::AutoCompSetIgnoreCase( bool ignoreCase ) {
  SendMsg( SCI_AUTOCSETIGNORECASE, ignoreCase, 0 );
}


bool wxScintilla::AutoCompGetIgnoreCase() const {
  return SendMsg( SCI_AUTOCGETIGNORECASE, 0, 0 ) != 0;
}

void wxScintilla::UserListShow( int listType, const wxString& itemList ) {
  SendMsg( SCI_USERLISTSHOW, listType, ( uptr_t )( const char* )wx2sci( itemList ) );
}

void wxScintilla::AutoCompSetAutoHide( bool autoHide ) {
  SendMsg( SCI_AUTOCSETAUTOHIDE, autoHide, 0 );
}


bool wxScintilla::AutoCompGetAutoHide() const {
  return SendMsg( SCI_AUTOCGETAUTOHIDE, 0, 0 ) != 0;
}


void wxScintilla::AutoCompSetDropRestOfWord( bool dropRestOfWord ) {
  SendMsg( SCI_AUTOCSETDROPRESTOFWORD, dropRestOfWord, 0 );
}


bool wxScintilla::AutoCompGetDropRestOfWord() const {
  return SendMsg( SCI_AUTOCGETDROPRESTOFWORD, 0, 0 ) != 0;
}

void wxScintilla::RegisterImage( int type, const wxBitmap& bmp ) {
  wxMemoryOutputStream strm;
  wxImage img = bmp.ConvertToImage();
  if( img.HasAlpha() ) {
    img.ConvertAlphaToMask();
  }
  img.SaveFile( strm, wxBITMAP_TYPE_XPM );
  size_t len = strm.GetSize();
  char* buff = new char[len + 1];
  strm.CopyTo( buff, len );
  buff[len] = 0;
  SendMsg( SCI_REGISTERIMAGE, type, ( uptr_t )buff );
  delete [] buff;
}

void wxScintilla::ClearRegisteredImages() {
  SendMsg( SCI_CLEARREGISTEREDIMAGES, 0, 0 );
}


int wxScintilla::AutoCompGetTypeSeparator() const {
  return SendMsg( SCI_AUTOCGETTYPESEPARATOR, 0, 0 );
}


void wxScintilla::AutoCompSetTypeSeparator( int separatorCharacter ) {
  SendMsg( SCI_AUTOCSETTYPESEPARATOR, separatorCharacter, 0 );
}


void wxScintilla::AutoCompSetMaxWidth( int characterCount ) {
  SendMsg( SCI_AUTOCSETMAXWIDTH, characterCount, 0 );
}


int wxScintilla::AutoCompGetMaxWidth() const {
  return SendMsg( SCI_AUTOCGETMAXWIDTH, 0, 0 );
}


void wxScintilla::AutoCompSetMaxHeight( int rowCount ) {
  SendMsg( SCI_AUTOCSETMAXHEIGHT, rowCount, 0 );
}


int wxScintilla::AutoCompGetMaxHeight() const {
  return SendMsg( SCI_AUTOCGETMAXHEIGHT, 0, 0 );
}

void wxScintilla::SetIndent( int indentSize ) {
  SendMsg( SCI_SETINDENT, indentSize, 0 );
}


int wxScintilla::GetIndent() const {
  return SendMsg( SCI_GETINDENT, 0, 0 );
}


void wxScintilla::SetUseTabs( bool useTabs ) {
  SendMsg( SCI_SETUSETABS, useTabs, 0 );
}


bool wxScintilla::GetUseTabs() const {
  return SendMsg( SCI_GETUSETABS, 0, 0 ) != 0;
}

void wxScintilla::SetLineIndentation( int line, int indentSize ) {
  SendMsg( SCI_SETLINEINDENTATION, line, indentSize );
}


int wxScintilla::GetLineIndentation( int line ) const {
  return SendMsg( SCI_GETLINEINDENTATION, line, 0 );
}


int wxScintilla::GetLineIndentPosition( int line ) const {
  return SendMsg( SCI_GETLINEINDENTPOSITION, line, 0 );
}


int wxScintilla::GetColumn( int pos ) const {
  return SendMsg( SCI_GETCOLUMN, pos, 0 );
}


int wxScintilla::CountCharacters( int startPos, int endPos ) {
  return SendMsg( SCI_COUNTCHARACTERS, startPos, endPos );
}

void wxScintilla::SetUseHorizontalScrollBar( bool show ) {
  SendMsg( SCI_SETHSCROLLBAR, show, 0 );
}


bool wxScintilla::GetUseHorizontalScrollBar() const {
  return SendMsg( SCI_GETHSCROLLBAR, 0, 0 ) != 0;
}

void wxScintilla::SetIndentationGuides( int indentView ) {
  SendMsg( SCI_SETINDENTATIONGUIDES, indentView, 0 );
}


int wxScintilla::GetIndentationGuides() const {
  return SendMsg( SCI_GETINDENTATIONGUIDES, 0, 0 );
}


void wxScintilla::SetHighlightGuide( int column ) {
  SendMsg( SCI_SETHIGHLIGHTGUIDE, column, 0 );
}


int wxScintilla::GetHighlightGuide() const {
  return SendMsg( SCI_GETHIGHLIGHTGUIDE, 0, 0 );
}


int wxScintilla::GetLineEndPosition( int line ) const {
  return SendMsg( SCI_GETLINEENDPOSITION, line, 0 );
}


int wxScintilla::GetCodePage() const {
  return SendMsg( SCI_GETCODEPAGE, 0, 0 );
}


wxColour wxScintilla::GetCaretForeground() const {
  long c = SendMsg( SCI_GETCARETFORE, 0, 0 );
  return wxColourFromLong( c );
}


bool wxScintilla::GetReadOnly() const {
  return SendMsg( SCI_GETREADONLY, 0, 0 ) != 0;
}

void wxScintilla::SetCurrentPos( int pos ) {
  SendMsg( SCI_SETCURRENTPOS, pos, 0 );
}

void wxScintilla::SetSelectionStart( int pos ) {
  SendMsg( SCI_SETSELECTIONSTART, pos, 0 );
}


int wxScintilla::GetSelectionStart() const {
  return SendMsg( SCI_GETSELECTIONSTART, 0, 0 );
}

void wxScintilla::SetSelectionEnd( int pos ) {
  SendMsg( SCI_SETSELECTIONEND, pos, 0 );
}


int wxScintilla::GetSelectionEnd() const {
  return SendMsg( SCI_GETSELECTIONEND, 0, 0 );
}

void wxScintilla::SetEmptySelection( int pos ) {
  SendMsg( SCI_SETEMPTYSELECTION, pos, 0 );
}

void wxScintilla::SetPrintMagnification( int magnification ) {
  SendMsg( SCI_SETPRINTMAGNIFICATION, magnification, 0 );
}


int wxScintilla::GetPrintMagnification() const {
  return SendMsg( SCI_GETPRINTMAGNIFICATION, 0, 0 );
}

void wxScintilla::SetPrintColourMode( int mode ) {
  SendMsg( SCI_SETPRINTCOLOURMODE, mode, 0 );
}


int wxScintilla::GetPrintColourMode() const {
  return SendMsg( SCI_GETPRINTCOLOURMODE, 0, 0 );
}


int wxScintilla::FindText( int minPos, int maxPos,
                           const wxString& text,
                           int flags,

                           int* lengthFound )

{
  TextToFind  ft;
  ft.chrg.cpMin = minPos;
  ft.chrg.cpMax = maxPos;
  const wxWX2MBbuf buf = wx2sci( text );
  ft.lpstrText = ( char* )( const char* )buf;
  int ret = SendMsg( SCI_FINDTEXT, flags, ( uptr_t )&ft );
  if( lengthFound ) {
    *lengthFound = ft.chrgText.cpMax - ft.chrgText.cpMin;
  }
  return ret;
}


int wxScintilla::FormatRange( bool doDraw,
                              int startPos,
                              int endPos,
                              wxDC* draw,
                              wxDC* target,
                              wxRect renderRect,
                              wxRect pageRect ) {
  RangeToFormat fr;
  if( endPos < startPos ) {
    int temp = startPos;
    startPos = endPos;
    endPos = temp;
  }
  fr.hdc = draw;
  fr.hdcTarget = target;
  fr.rc.top = renderRect.GetTop();
  fr.rc.left = renderRect.GetLeft();
  fr.rc.right = renderRect.GetRight();
  fr.rc.bottom = renderRect.GetBottom();
  fr.rcPage.top = pageRect.GetTop();
  fr.rcPage.left = pageRect.GetLeft();
  fr.rcPage.right = pageRect.GetRight();
  fr.rcPage.bottom = pageRect.GetBottom();
  fr.chrg.cpMin = startPos;
  fr.chrg.cpMax = endPos;
  return SendMsg( SCI_FORMATRANGE, doDraw, ( uptr_t )&fr );
}


int wxScintilla::GetFirstVisibleLine() const {
  return SendMsg( SCI_GETFIRSTVISIBLELINE, 0, 0 );
}


wxString wxScintilla::GetLine( int line ) const {
  int len = LineLength( line );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETLINE, line, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


int wxScintilla::GetLineCount() const {
  return SendMsg( SCI_GETLINECOUNT, 0, 0 );
}

void wxScintilla::SetMarginLeft( int pixelWidth ) {
  SendMsg( SCI_SETMARGINLEFT, 0, pixelWidth );
}


int wxScintilla::GetMarginLeft() const {
  return SendMsg( SCI_GETMARGINLEFT, 0, 0 );
}

void wxScintilla::SetMarginRight( int pixelWidth ) {
  SendMsg( SCI_SETMARGINRIGHT, 0, pixelWidth );
}


int wxScintilla::GetMarginRight() const {
  return SendMsg( SCI_GETMARGINRIGHT, 0, 0 );
}


bool wxScintilla::GetModify() const {
  return SendMsg( SCI_GETMODIFY, 0, 0 ) != 0;
}


wxString wxScintilla::GetSelectedText() {
  const long len = SendMsg( SCI_GETSELTEXT, 0, ( uptr_t )0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 2 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETSELTEXT, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


wxString wxScintilla::GetTextRange( int startPos, int endPos ) {
  if( endPos < startPos ) {
    int temp = startPos;
    startPos = endPos;
    endPos = temp;
  }
  int   len  = endPos - startPos;
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len );
  TextRange tr;
  tr.lpstrText = buf;
  tr.chrg.cpMin = startPos;
  tr.chrg.cpMax = endPos;
  SendMsg( SCI_GETTEXTRANGE, 0, ( uptr_t )&tr );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::HideSelection( bool normal ) {
  SendMsg( SCI_HIDESELECTION, normal, 0 );
}


int wxScintilla::LineFromPosition( int pos ) const {
  return SendMsg( SCI_LINEFROMPOSITION, pos, 0 );
}


int wxScintilla::PositionFromLine( int line ) const {
  return SendMsg( SCI_POSITIONFROMLINE, line, 0 );
}

void wxScintilla::LineScroll( int columns, int lines ) {
  SendMsg( SCI_LINESCROLL, columns, lines );
}

void wxScintilla::EnsureCaretVisible() {
  SendMsg( SCI_SCROLLCARET, 0, 0 );
}


void wxScintilla::ScrollRange( int secondary, int primary ) {
  SendMsg( SCI_SCROLLRANGE, secondary, primary );
}

void wxScintilla::ReplaceSelection( const wxString& text ) {
  SendMsg( SCI_REPLACESEL, 0, ( uptr_t )( const char* )wx2sci( text ) );
}

void wxScintilla::SetReadOnly( bool readOnly ) {
  SendMsg( SCI_SETREADONLY, readOnly, 0 );
}


bool wxScintilla::CanPaste() const {
  return SendMsg( SCI_CANPASTE, 0, 0 ) != 0;
}


bool wxScintilla::CanUndo() const {
  return SendMsg( SCI_CANUNDO, 0, 0 ) != 0;
}


void wxScintilla::EmptyUndoBuffer( bool collectChangeHistory ) {
  SendMsg( SCI_EMPTYUNDOBUFFER, collectChangeHistory, 0 );
}


void wxScintilla::Undo() {
  SendMsg( SCI_UNDO, 0, 0 );
}

void wxScintilla::Cut() {
  SendMsg( SCI_CUT, 0, 0 );
}

void wxScintilla::Copy() {
  SendMsg( SCI_COPY, 0, 0 );
}

void wxScintilla::Paste() {
  SendMsg( SCI_PASTE, 0, 0 );
}

void wxScintilla::Clear() {
  SendMsg( SCI_CLEAR, 0, 0 );
}

void wxScintilla::SetText( const wxString& text ) {
  SendMsg( SCI_SETTEXT, 0, ( uptr_t )( const char* )wx2sci( text ) );
}


wxString wxScintilla::GetText() const {
  int len = GetTextLength();
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETTEXT, len + 1, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


int wxScintilla::GetTextLength() const {
  return SendMsg( SCI_GETTEXTLENGTH, 0, 0 );
}

void wxScintilla::SetOvertype( bool overtype ) {
  SendMsg( SCI_SETOVERTYPE, overtype, 0 );
}


bool wxScintilla::GetOvertype() const {
  return SendMsg( SCI_GETOVERTYPE, 0, 0 ) != 0;
}

void wxScintilla::SetCaretWidth( int pixelWidth ) {
  SendMsg( SCI_SETCARETWIDTH, pixelWidth, 0 );
}


int wxScintilla::GetCaretWidth() const {
  return SendMsg( SCI_GETCARETWIDTH, 0, 0 );
}


void wxScintilla::SetTargetStart( int pos ) {
  SendMsg( SCI_SETTARGETSTART, pos, 0 );
}


int wxScintilla::GetTargetStart() const {
  return SendMsg( SCI_GETTARGETSTART, 0, 0 );
}


void wxScintilla::SetTargetEnd( int pos ) {
  SendMsg( SCI_SETTARGETEND, pos, 0 );
}


int wxScintilla::GetTargetEnd() const {
  return SendMsg( SCI_GETTARGETEND, 0, 0 );
}



int wxScintilla::ReplaceTarget( const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  return SendMsg( SCI_REPLACETARGET, strlen( buf ), ( uptr_t )( const char* )buf );
}



int wxScintilla::ReplaceTargetRE( const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  return SendMsg( SCI_REPLACETARGETRE, strlen( buf ), ( uptr_t )( const char* )buf );
}



int wxScintilla::SearchInTarget( const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  return SendMsg( SCI_SEARCHINTARGET, strlen( buf ), ( uptr_t )( const char* )buf );
}

void wxScintilla::SetSearchFlags( int flags ) {
  SendMsg( SCI_SETSEARCHFLAGS, flags, 0 );
}


int wxScintilla::GetSearchFlags() const {
  return SendMsg( SCI_GETSEARCHFLAGS, 0, 0 );
}

void wxScintilla::CallTipShow( int pos, const wxString& definition ) {
  SendMsg( SCI_CALLTIPSHOW, pos, ( uptr_t )( const char* )wx2sci( definition ) );
}

void wxScintilla::CallTipCancel() {
  SendMsg( SCI_CALLTIPCANCEL, 0, 0 );
}


bool wxScintilla::CallTipActive() {
  return SendMsg( SCI_CALLTIPACTIVE, 0, 0 ) != 0;
}


int wxScintilla::CallTipPosAtStart() {
  return SendMsg( SCI_CALLTIPPOSSTART, 0, 0 );
}

void wxScintilla::CallTipSetPosAtStart( int posStart ) {
  SendMsg( SCI_CALLTIPSETPOSSTART, posStart, 0 );
}

void wxScintilla::CallTipSetHighlight( int start, int end ) {
  SendMsg( SCI_CALLTIPSETHLT, start, end );
}

void wxScintilla::CallTipSetBackground( const wxColour& back ) {
  SendMsg( SCI_CALLTIPSETBACK, wxColourAsLong( back ), 0 );
}

void wxScintilla::CallTipSetForeground( const wxColour& fore ) {
  SendMsg( SCI_CALLTIPSETFORE, wxColourAsLong( fore ), 0 );
}

void wxScintilla::CallTipSetForegroundHighlight( const wxColour& fore ) {
  SendMsg( SCI_CALLTIPSETFOREHLT, wxColourAsLong( fore ), 0 );
}

void wxScintilla::CallTipUseStyle( int tabSize ) {
  SendMsg( SCI_CALLTIPUSESTYLE, tabSize, 0 );
}

void wxScintilla::CallTipSetPosition( bool above ) {
  SendMsg( SCI_CALLTIPSETPOSITION, above, 0 );
}


int wxScintilla::VisibleFromDocLine( int line ) {
  return SendMsg( SCI_VISIBLEFROMDOCLINE, line, 0 );
}


int wxScintilla::DocLineFromVisible( int lineDisplay ) {
  return SendMsg( SCI_DOCLINEFROMVISIBLE, lineDisplay, 0 );
}


int wxScintilla::WrapCount( int line ) {
  return SendMsg( SCI_WRAPCOUNT, line, 0 );
}


void wxScintilla::SetFoldLevel( int line, int level ) {
  SendMsg( SCI_SETFOLDLEVEL, line, level );
}


int wxScintilla::GetFoldLevel( int line ) const {
  return SendMsg( SCI_GETFOLDLEVEL, line, 0 );
}


int wxScintilla::GetLastChild( int line, int level ) const {
  return SendMsg( SCI_GETLASTCHILD, line, level );
}


int wxScintilla::GetFoldParent( int line ) const {
  return SendMsg( SCI_GETFOLDPARENT, line, 0 );
}

void wxScintilla::ShowLines( int lineStart, int lineEnd ) {
  SendMsg( SCI_SHOWLINES, lineStart, lineEnd );
}

void wxScintilla::HideLines( int lineStart, int lineEnd ) {
  SendMsg( SCI_HIDELINES, lineStart, lineEnd );
}


bool wxScintilla::GetLineVisible( int line ) const {
  return SendMsg( SCI_GETLINEVISIBLE, line, 0 ) != 0;
}


bool wxScintilla::GetAllLinesVisible() const {
  return SendMsg( SCI_GETALLLINESVISIBLE, 0, 0 ) != 0;
}

void wxScintilla::SetFoldExpanded( int line, bool expanded ) {
  SendMsg( SCI_SETFOLDEXPANDED, line, expanded );
}


bool wxScintilla::GetFoldExpanded( int line ) const {
  return SendMsg( SCI_GETFOLDEXPANDED, line, 0 ) != 0;
}

void wxScintilla::ToggleFold( int line ) {
  SendMsg( SCI_TOGGLEFOLD, line, 0 );
}

void wxScintilla::FoldLine( int line, int action ) {
  SendMsg( SCI_FOLDLINE, line, action );
}

void wxScintilla::FoldChildren( int line, int action ) {
  SendMsg( SCI_FOLDCHILDREN, line, action );
}

void wxScintilla::ExpandChildren( int line, int level ) {
  SendMsg( SCI_EXPANDCHILDREN, line, level );
}

void wxScintilla::FoldAll( int action ) {
  SendMsg( SCI_FOLDALL, action, 0 );
}

void wxScintilla::EnsureVisible( int line ) {
  SendMsg( SCI_ENSUREVISIBLE, line, 0 );
}

void wxScintilla::SetAutomaticFold( int automaticFold ) {
  SendMsg( SCI_SETAUTOMATICFOLD, automaticFold, 0 );
}


int wxScintilla::GetAutomaticFold() const {
  return SendMsg( SCI_GETAUTOMATICFOLD, 0, 0 );
}

void wxScintilla::SetFoldFlags( int flags ) {
  SendMsg( SCI_SETFOLDFLAGS, flags, 0 );
}


void wxScintilla::EnsureVisibleEnforcePolicy( int line ) {
  SendMsg( SCI_ENSUREVISIBLEENFORCEPOLICY, line, 0 );
}

void wxScintilla::SetTabIndents( bool tabIndents ) {
  SendMsg( SCI_SETTABINDENTS, tabIndents, 0 );
}


bool wxScintilla::GetTabIndents() const {
  return SendMsg( SCI_GETTABINDENTS, 0, 0 ) != 0;
}

void wxScintilla::SetBackSpaceUnIndents( bool bsUnIndents ) {
  SendMsg( SCI_SETBACKSPACEUNINDENTS, bsUnIndents, 0 );
}


bool wxScintilla::GetBackSpaceUnIndents() const {
  return SendMsg( SCI_GETBACKSPACEUNINDENTS, 0, 0 ) != 0;
}

void wxScintilla::SetMouseDwellTime( int periodMilliseconds ) {
  SendMsg( SCI_SETMOUSEDWELLTIME, periodMilliseconds, 0 );
}


int wxScintilla::GetMouseDwellTime() const {
  return SendMsg( SCI_GETMOUSEDWELLTIME, 0, 0 );
}


int wxScintilla::WordStartPosition( int pos, bool onlyWordCharacters ) {
  return SendMsg( SCI_WORDSTARTPOSITION, pos, onlyWordCharacters );
}


int wxScintilla::WordEndPosition( int pos, bool onlyWordCharacters ) {
  return SendMsg( SCI_WORDENDPOSITION, pos, onlyWordCharacters );
}

void wxScintilla::SetWrapMode( int mode ) {
  SendMsg( SCI_SETWRAPMODE, mode, 0 );
}


int wxScintilla::GetWrapMode() const {
  return SendMsg( SCI_GETWRAPMODE, 0, 0 );
}

void wxScintilla::SetWrapVisualFlags( int wrapVisualFlags ) {
  SendMsg( SCI_SETWRAPVISUALFLAGS, wrapVisualFlags, 0 );
}


int wxScintilla::GetWrapVisualFlags() const {
  return SendMsg( SCI_GETWRAPVISUALFLAGS, 0, 0 );
}

void wxScintilla::SetWrapVisualFlagsLocation( int wrapVisualFlagsLocation ) {
  SendMsg( SCI_SETWRAPVISUALFLAGSLOCATION, wrapVisualFlagsLocation, 0 );
}


int wxScintilla::GetWrapVisualFlagsLocation() const {
  return SendMsg( SCI_GETWRAPVISUALFLAGSLOCATION, 0, 0 );
}

void wxScintilla::SetWrapStartIndent( int indent ) {
  SendMsg( SCI_SETWRAPSTARTINDENT, indent, 0 );
}


int wxScintilla::GetWrapStartIndent() const {
  return SendMsg( SCI_GETWRAPSTARTINDENT, 0, 0 );
}

void wxScintilla::SetWrapIndentMode( int mode ) {
  SendMsg( SCI_SETWRAPINDENTMODE, mode, 0 );
}


int wxScintilla::GetWrapIndentMode() const {
  return SendMsg( SCI_GETWRAPINDENTMODE, 0, 0 );
}

void wxScintilla::SetLayoutCache( int mode ) {
  SendMsg( SCI_SETLAYOUTCACHE, mode, 0 );
}


int wxScintilla::GetLayoutCache() const {
  return SendMsg( SCI_GETLAYOUTCACHE, 0, 0 );
}

void wxScintilla::SetScrollWidth( int pixelWidth ) {
  SendMsg( SCI_SETSCROLLWIDTH, pixelWidth, 0 );
}


int wxScintilla::GetScrollWidth() const {
  return SendMsg( SCI_GETSCROLLWIDTH, 0, 0 );
}

void wxScintilla::SetScrollWidthTracking( bool tracking ) {
  SendMsg( SCI_SETSCROLLWIDTHTRACKING, tracking, 0 );
}


bool wxScintilla::GetScrollWidthTracking() const {
  return SendMsg( SCI_GETSCROLLWIDTHTRACKING, 0, 0 ) != 0;
}


int wxScintilla::TextWidth( int style, const wxString& text ) {
  return SendMsg( SCI_TEXTWIDTH, style, ( uptr_t )( const char* )wx2sci( text ) );
}


void wxScintilla::SetEndAtLastLine( bool endAtLastLine ) {
  SendMsg( SCI_SETENDATLASTLINE, endAtLastLine, 0 );
}


bool wxScintilla::GetEndAtLastLine() const {
  return SendMsg( SCI_GETENDATLASTLINE, 0, 0 ) != 0;
}


int wxScintilla::TextHeight( int line ) {
  return SendMsg( SCI_TEXTHEIGHT, line, 0 );
}

void wxScintilla::SetUseVerticalScrollBar( bool show ) {
  SendMsg( SCI_SETVSCROLLBAR, show, 0 );
}


bool wxScintilla::GetUseVerticalScrollBar() const {
  return SendMsg( SCI_GETVSCROLLBAR, 0, 0 ) != 0;
}

void wxScintilla::AppendText( const wxString& text ) {
  const wxWX2MBbuf buf = wx2sci( text );
  SendMsg( SCI_APPENDTEXT, strlen( buf ), ( uptr_t )( const char* )buf );
}


bool wxScintilla::GetTwoPhaseDraw() const {
  return SendMsg( SCI_GETTWOPHASEDRAW, 0, 0 ) != 0;
}


void wxScintilla::SetTwoPhaseDraw( bool twoPhase ) {
  SendMsg( SCI_SETTWOPHASEDRAW, twoPhase, 0 );
}


int wxScintilla::GetPhasesDraw() const {
  return SendMsg( SCI_GETPHASESDRAW, 0, 0 );
}


void wxScintilla::SetPhasesDraw( int phases ) {
  SendMsg( SCI_SETPHASESDRAW, phases, 0 );
}

void wxScintilla::SetFirstVisibleLine( int lineDisplay ) {
  SendMsg( SCI_SETFIRSTVISIBLELINE, lineDisplay, 0 );
}

void wxScintilla::SetMultiPaste( int multiPaste ) {
  SendMsg( SCI_SETMULTIPASTE, multiPaste, 0 );
}


int wxScintilla::GetMultiPaste() const {
  return SendMsg( SCI_GETMULTIPASTE, 0, 0 );
}


wxString wxScintilla::GetTag( int tagNumber ) const {
  const int msg = SCI_GETTAG;
  const long len = SendMsg( msg, tagNumber, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, tagNumber, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


void wxScintilla::SetFontQuality( int fontQuality ) {
  SendMsg( SCI_SETFONTQUALITY, fontQuality, 0 );
}


int wxScintilla::GetFontQuality() const {
  return SendMsg( SCI_GETFONTQUALITY, 0, 0 );
}


void wxScintilla::TargetFromSelection() {
  SendMsg( SCI_TARGETFROMSELECTION, 0, 0 );
}

void wxScintilla::LinesJoin() {
  SendMsg( SCI_LINESJOIN, 0, 0 );
}


void wxScintilla::LinesSplit( int pixelWidth ) {
  SendMsg( SCI_LINESSPLIT, pixelWidth, 0 );
}

void wxScintilla::SetFoldMarginColour( bool useSetting, const wxColour& back ) {
  SendMsg( SCI_SETFOLDMARGINCOLOUR, useSetting, wxColourAsLong( back ) );
}

void wxScintilla::SetFoldMarginHiColour( bool useSetting, const wxColour& fore ) {
  SendMsg( SCI_SETFOLDMARGINHICOLOUR, useSetting, wxColourAsLong( fore ) );
}

void wxScintilla::LineDown() {
  SendMsg( SCI_LINEDOWN, 0, 0 );
}

void wxScintilla::LineDownExtend() {
  SendMsg( SCI_LINEDOWNEXTEND, 0, 0 );
}

void wxScintilla::LineUp() {
  SendMsg( SCI_LINEUP, 0, 0 );
}

void wxScintilla::LineUpExtend() {
  SendMsg( SCI_LINEUPEXTEND, 0, 0 );
}

void wxScintilla::CharLeft() {
  SendMsg( SCI_CHARLEFT, 0, 0 );
}

void wxScintilla::CharLeftExtend() {
  SendMsg( SCI_CHARLEFTEXTEND, 0, 0 );
}

void wxScintilla::CharRight() {
  SendMsg( SCI_CHARRIGHT, 0, 0 );
}

void wxScintilla::CharRightExtend() {
  SendMsg( SCI_CHARRIGHTEXTEND, 0, 0 );
}

void wxScintilla::WordLeft() {
  SendMsg( SCI_WORDLEFT, 0, 0 );
}

void wxScintilla::WordLeftExtend() {
  SendMsg( SCI_WORDLEFTEXTEND, 0, 0 );
}

void wxScintilla::WordRight() {
  SendMsg( SCI_WORDRIGHT, 0, 0 );
}

void wxScintilla::WordRightExtend() {
  SendMsg( SCI_WORDRIGHTEXTEND, 0, 0 );
}

void wxScintilla::Home() {
  SendMsg( SCI_HOME, 0, 0 );
}

void wxScintilla::HomeExtend() {
  SendMsg( SCI_HOMEEXTEND, 0, 0 );
}

void wxScintilla::LineEnd() {
  SendMsg( SCI_LINEEND, 0, 0 );
}

void wxScintilla::LineEndExtend() {
  SendMsg( SCI_LINEENDEXTEND, 0, 0 );
}

void wxScintilla::DocumentStart() {
  SendMsg( SCI_DOCUMENTSTART, 0, 0 );
}

void wxScintilla::DocumentStartExtend() {
  SendMsg( SCI_DOCUMENTSTARTEXTEND, 0, 0 );
}

void wxScintilla::DocumentEnd() {
  SendMsg( SCI_DOCUMENTEND, 0, 0 );
}

void wxScintilla::DocumentEndExtend() {
  SendMsg( SCI_DOCUMENTENDEXTEND, 0, 0 );
}

void wxScintilla::PageUp() {
  SendMsg( SCI_PAGEUP, 0, 0 );
}

void wxScintilla::PageUpExtend() {
  SendMsg( SCI_PAGEUPEXTEND, 0, 0 );
}

void wxScintilla::PageDown() {
  SendMsg( SCI_PAGEDOWN, 0, 0 );
}

void wxScintilla::PageDownExtend() {
  SendMsg( SCI_PAGEDOWNEXTEND, 0, 0 );
}

void wxScintilla::EditToggleOvertype() {
  SendMsg( SCI_EDITTOGGLEOVERTYPE, 0, 0 );
}

void wxScintilla::Cancel() {
  SendMsg( SCI_CANCEL, 0, 0 );
}

void wxScintilla::DeleteBack() {
  SendMsg( SCI_DELETEBACK, 0, 0 );
}


void wxScintilla::Tab() {
  SendMsg( SCI_TAB, 0, 0 );
}

void wxScintilla::BackTab() {
  SendMsg( SCI_BACKTAB, 0, 0 );
}

void wxScintilla::NewLine() {
  SendMsg( SCI_NEWLINE, 0, 0 );
}

void wxScintilla::FormFeed() {
  SendMsg( SCI_FORMFEED, 0, 0 );
}


void wxScintilla::VCHome() {
  SendMsg( SCI_VCHOME, 0, 0 );
}

void wxScintilla::VCHomeExtend() {
  SendMsg( SCI_VCHOMEEXTEND, 0, 0 );
}

void wxScintilla::ZoomIn() {
  SendMsg( SCI_ZOOMIN, 0, 0 );
}

void wxScintilla::ZoomOut() {
  SendMsg( SCI_ZOOMOUT, 0, 0 );
}

void wxScintilla::DelWordLeft() {
  SendMsg( SCI_DELWORDLEFT, 0, 0 );
}

void wxScintilla::DelWordRight() {
  SendMsg( SCI_DELWORDRIGHT, 0, 0 );
}

void wxScintilla::DelWordRightEnd() {
  SendMsg( SCI_DELWORDRIGHTEND, 0, 0 );
}

void wxScintilla::LineCut() {
  SendMsg( SCI_LINECUT, 0, 0 );
}

void wxScintilla::LineDelete() {
  SendMsg( SCI_LINEDELETE, 0, 0 );
}

void wxScintilla::LineTranspose() {
  SendMsg( SCI_LINETRANSPOSE, 0, 0 );
}

void wxScintilla::LineDuplicate() {
  SendMsg( SCI_LINEDUPLICATE, 0, 0 );
}

void wxScintilla::LowerCase() {
  SendMsg( SCI_LOWERCASE, 0, 0 );
}

void wxScintilla::UpperCase() {
  SendMsg( SCI_UPPERCASE, 0, 0 );
}

void wxScintilla::LineScrollDown() {
  SendMsg( SCI_LINESCROLLDOWN, 0, 0 );
}

void wxScintilla::LineScrollUp() {
  SendMsg( SCI_LINESCROLLUP, 0, 0 );
}


void wxScintilla::DeleteBackNotLine() {
  SendMsg( SCI_DELETEBACKNOTLINE, 0, 0 );
}

void wxScintilla::HomeDisplay() {
  SendMsg( SCI_HOMEDISPLAY, 0, 0 );
}


void wxScintilla::HomeDisplayExtend() {
  SendMsg( SCI_HOMEDISPLAYEXTEND, 0, 0 );
}

void wxScintilla::LineEndDisplay() {
  SendMsg( SCI_LINEENDDISPLAY, 0, 0 );
}


void wxScintilla::LineEndDisplayExtend() {
  SendMsg( SCI_LINEENDDISPLAYEXTEND, 0, 0 );
}


void wxScintilla::HomeWrap() {
  SendMsg( SCI_HOMEWRAP, 0, 0 );
}

void wxScintilla::HomeWrapExtend() {
  SendMsg( SCI_HOMEWRAPEXTEND, 0, 0 );
}

void wxScintilla::LineEndWrap() {
  SendMsg( SCI_LINEENDWRAP, 0, 0 );
}

void wxScintilla::LineEndWrapExtend() {
  SendMsg( SCI_LINEENDWRAPEXTEND, 0, 0 );
}

void wxScintilla::VCHomeWrap() {
  SendMsg( SCI_VCHOMEWRAP, 0, 0 );
}

void wxScintilla::VCHomeWrapExtend() {
  SendMsg( SCI_VCHOMEWRAPEXTEND, 0, 0 );
}

void wxScintilla::LineCopy() {
  SendMsg( SCI_LINECOPY, 0, 0 );
}

void wxScintilla::MoveCaretInsideView() {
  SendMsg( SCI_MOVECARETINSIDEVIEW, 0, 0 );
}


int wxScintilla::LineLength( int line ) const {
  return SendMsg( SCI_LINELENGTH, line, 0 );
}

void wxScintilla::BraceHighlight( int pos1, int pos2 ) {
  SendMsg( SCI_BRACEHIGHLIGHT, pos1, pos2 );
}

void wxScintilla::BraceHighlightIndicator( bool useBraceHighlightIndicator, int indicator ) {
  SendMsg( SCI_BRACEHIGHLIGHTINDICATOR, useBraceHighlightIndicator, indicator );
}

void wxScintilla::BraceBadLight( int pos ) {
  SendMsg( SCI_BRACEBADLIGHT, pos, 0 );
}

void wxScintilla::BraceBadLightIndicator( bool useBraceBadLightIndicator, int indicator ) {
  SendMsg( SCI_BRACEBADLIGHTINDICATOR, useBraceBadLightIndicator, indicator );
}


int wxScintilla::BraceMatch( int pos ) {
  return SendMsg( SCI_BRACEMATCH, pos, 0 );
}


bool wxScintilla::GetViewEOL() const {
  return SendMsg( SCI_GETVIEWEOL, 0, 0 ) != 0;
}

void wxScintilla::SetViewEOL( bool visible ) {
  SendMsg( SCI_SETVIEWEOL, visible, 0 );
}

void* wxScintilla::GetDocPointer() {
  return ( void* )SendMsg( SCI_GETDOCPOINTER );
}

void wxScintilla::SetDocPointer( void* docPointer ) {
  SendMsg( SCI_SETDOCPOINTER, 0, ( uptr_t )docPointer );
}

void wxScintilla::SetModEventMask( int mask ) {
  SendMsg( SCI_SETMODEVENTMASK, mask, 0 );
}


int wxScintilla::GetEdgeColumn() const {
  return SendMsg( SCI_GETEDGECOLUMN, 0, 0 );
}


void wxScintilla::SetEdgeColumn( int column ) {
  SendMsg( SCI_SETEDGECOLUMN, column, 0 );
}


int wxScintilla::GetEdgeMode() const {
  return SendMsg( SCI_GETEDGEMODE, 0, 0 );
}


void wxScintilla::SetEdgeMode( int mode ) {
  SendMsg( SCI_SETEDGEMODE, mode, 0 );
}


wxColour wxScintilla::GetEdgeColour() const {
  long c = SendMsg( SCI_GETEDGECOLOUR, 0, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::SetEdgeColour( const wxColour& edgeColour ) {
  SendMsg( SCI_SETEDGECOLOUR, wxColourAsLong( edgeColour ), 0 );
}

void wxScintilla::SearchAnchor() {
  SendMsg( SCI_SEARCHANCHOR, 0, 0 );
}


int wxScintilla::SearchNext( int flags, const wxString& text ) {
  return SendMsg( SCI_SEARCHNEXT, flags, ( uptr_t )( const char* )wx2sci( text ) );
}


int wxScintilla::SearchPrev( int flags, const wxString& text ) {
  return SendMsg( SCI_SEARCHPREV, flags, ( uptr_t )( const char* )wx2sci( text ) );
}


int wxScintilla::LinesOnScreen() const {
  return SendMsg( SCI_LINESONSCREEN, 0, 0 );
}


void wxScintilla::UsePopUp( bool allowPopUp ) {
  SendMsg( SCI_USEPOPUP, allowPopUp, 0 );
}


bool wxScintilla::SelectionIsRectangle() const {
  return SendMsg( SCI_SELECTIONISRECTANGLE, 0, 0 ) != 0;
}


void wxScintilla::SetZoom( int zoom ) {
  SendMsg( SCI_SETZOOM, zoom, 0 );
}


int wxScintilla::GetZoom() const {
  return SendMsg( SCI_GETZOOM, 0, 0 );
}


void* wxScintilla::CreateDocument() {
  return ( void* )SendMsg( SCI_CREATEDOCUMENT );
}

void wxScintilla::AddRefDocument( void* docPointer ) {
  SendMsg( SCI_ADDREFDOCUMENT, 0, ( uptr_t )docPointer );
}

void wxScintilla::ReleaseDocument( void* docPointer ) {
  SendMsg( SCI_RELEASEDOCUMENT, 0, ( uptr_t )docPointer );
}


int wxScintilla::GetModEventMask() const {
  return SendMsg( SCI_GETMODEVENTMASK, 0, 0 );
}

void wxScintilla::SetSCIFocus( bool focus ) {
  SendMsg( SCI_SETFOCUS, focus, 0 );
}


bool wxScintilla::GetSCIFocus() const {
  return SendMsg( SCI_GETFOCUS, 0, 0 ) != 0;
}

void wxScintilla::SetStatus( int statusCode ) {
  SendMsg( SCI_SETSTATUS, statusCode, 0 );
}


int wxScintilla::GetStatus() const {
  return SendMsg( SCI_GETSTATUS, 0, 0 );
}

void wxScintilla::SetMouseDownCaptures( bool captures ) {
  SendMsg( SCI_SETMOUSEDOWNCAPTURES, captures, 0 );
}


bool wxScintilla::GetMouseDownCaptures() const {
  return SendMsg( SCI_GETMOUSEDOWNCAPTURES, 0, 0 ) != 0;
}

void wxScintilla::SetSCICursor( int cursorType ) {
  SendMsg( SCI_SETCURSOR, cursorType, 0 );
}


int wxScintilla::GetSCICursor() const {
  return SendMsg( SCI_GETCURSOR, 0, 0 );
}


void wxScintilla::SetControlCharSymbol( int symbol ) {
  SendMsg( SCI_SETCONTROLCHARSYMBOL, symbol, 0 );
}


int wxScintilla::GetControlCharSymbol() const {
  return SendMsg( SCI_GETCONTROLCHARSYMBOL, 0, 0 );
}

void wxScintilla::WordPartLeft() {
  SendMsg( SCI_WORDPARTLEFT, 0, 0 );
}


void wxScintilla::WordPartLeftExtend() {
  SendMsg( SCI_WORDPARTLEFTEXTEND, 0, 0 );
}

void wxScintilla::WordPartRight() {
  SendMsg( SCI_WORDPARTRIGHT, 0, 0 );
}


void wxScintilla::WordPartRightExtend() {
  SendMsg( SCI_WORDPARTRIGHTEXTEND, 0, 0 );
}


void wxScintilla::SetVisiblePolicy( int visiblePolicy, int visibleSlop ) {
  SendMsg( SCI_SETVISIBLEPOLICY, visiblePolicy, visibleSlop );
}

void wxScintilla::DelLineLeft() {
  SendMsg( SCI_DELLINELEFT, 0, 0 );
}

void wxScintilla::DelLineRight() {
  SendMsg( SCI_DELLINERIGHT, 0, 0 );
}

void wxScintilla::SetXOffset( int newOffset ) {
  SendMsg( SCI_SETXOFFSET, newOffset, 0 );
}
int wxScintilla::GetXOffset() const {
  return SendMsg( SCI_GETXOFFSET, 0, 0 );
}

void wxScintilla::ChooseCaretX() {
  SendMsg( SCI_CHOOSECARETX, 0, 0 );
}


void wxScintilla::SetXCaretPolicy( int caretPolicy, int caretSlop ) {
  SendMsg( SCI_SETXCARETPOLICY, caretPolicy, caretSlop );
}


void wxScintilla::SetYCaretPolicy( int caretPolicy, int caretSlop ) {
  SendMsg( SCI_SETYCARETPOLICY, caretPolicy, caretSlop );
}

void wxScintilla::SetPrintWrapMode( int mode ) {
  SendMsg( SCI_SETPRINTWRAPMODE, mode, 0 );
}


int wxScintilla::GetPrintWrapMode() const {
  return SendMsg( SCI_GETPRINTWRAPMODE, 0, 0 );
}

void wxScintilla::SetHotspotActiveForeground( bool useSetting, const wxColour& fore ) {
  SendMsg( SCI_SETHOTSPOTACTIVEFORE, useSetting, wxColourAsLong( fore ) );
}


wxColour wxScintilla::GetHotspotActiveForeground() const {
  long c = SendMsg( SCI_GETHOTSPOTACTIVEFORE, 0, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::SetHotspotActiveBackground( bool useSetting, const wxColour& back ) {
  SendMsg( SCI_SETHOTSPOTACTIVEBACK, useSetting, wxColourAsLong( back ) );
}


wxColour wxScintilla::GetHotspotActiveBackground() const {
  long c = SendMsg( SCI_GETHOTSPOTACTIVEBACK, 0, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::SetHotspotActiveUnderline( bool underline ) {
  SendMsg( SCI_SETHOTSPOTACTIVEUNDERLINE, underline, 0 );
}


bool wxScintilla::GetHotspotActiveUnderline() const {
  return SendMsg( SCI_GETHOTSPOTACTIVEUNDERLINE, 0, 0 ) != 0;
}

void wxScintilla::SetHotspotSingleLine( bool singleLine ) {
  SendMsg( SCI_SETHOTSPOTSINGLELINE, singleLine, 0 );
}


bool wxScintilla::GetHotspotSingleLine() const {
  return SendMsg( SCI_GETHOTSPOTSINGLELINE, 0, 0 ) != 0;
}

void wxScintilla::ParaDown() {
  SendMsg( SCI_PARADOWN, 0, 0 );
}

void wxScintilla::ParaDownExtend() {
  SendMsg( SCI_PARADOWNEXTEND, 0, 0 );
}

void wxScintilla::ParaUp() {
  SendMsg( SCI_PARAUP, 0, 0 );
}

void wxScintilla::ParaUpExtend() {
  SendMsg( SCI_PARAUPEXTEND, 0, 0 );
}


int wxScintilla::PositionBefore( int pos ) {
  return SendMsg( SCI_POSITIONBEFORE, pos, 0 );
}


int wxScintilla::PositionAfter( int pos ) {
  return SendMsg( SCI_POSITIONAFTER, pos, 0 );
}


int wxScintilla::PositionRelative( int pos, int relative ) {
  return SendMsg( SCI_POSITIONRELATIVE, pos, relative );
}

void wxScintilla::CopyRange( int start, int end ) {
  SendMsg( SCI_COPYRANGE, start, end );
}

void wxScintilla::CopyText( int length, const wxString& text ) {
  SendMsg( SCI_COPYTEXT, length, ( uptr_t )( const char* )wx2sci( text ) );
}


void wxScintilla::SetSelectionMode( int mode ) {
  SendMsg( SCI_SETSELECTIONMODE, mode, 0 );
}


int wxScintilla::GetSelectionMode() const {
  return SendMsg( SCI_GETSELECTIONMODE, 0, 0 );
}


int wxScintilla::GetLineSelStartPosition( int line ) {
  return SendMsg( SCI_GETLINESELSTARTPOSITION, line, 0 );
}


int wxScintilla::GetLineSelEndPosition( int line ) {
  return SendMsg( SCI_GETLINESELENDPOSITION, line, 0 );
}

void wxScintilla::LineDownRectExtend() {
  SendMsg( SCI_LINEDOWNRECTEXTEND, 0, 0 );
}

void wxScintilla::LineUpRectExtend() {
  SendMsg( SCI_LINEUPRECTEXTEND, 0, 0 );
}

void wxScintilla::CharLeftRectExtend() {
  SendMsg( SCI_CHARLEFTRECTEXTEND, 0, 0 );
}

void wxScintilla::CharRightRectExtend() {
  SendMsg( SCI_CHARRIGHTRECTEXTEND, 0, 0 );
}

void wxScintilla::HomeRectExtend() {
  SendMsg( SCI_HOMERECTEXTEND, 0, 0 );
}


void wxScintilla::VCHomeRectExtend() {
  SendMsg( SCI_VCHOMERECTEXTEND, 0, 0 );
}

void wxScintilla::LineEndRectExtend() {
  SendMsg( SCI_LINEENDRECTEXTEND, 0, 0 );
}

void wxScintilla::PageUpRectExtend() {
  SendMsg( SCI_PAGEUPRECTEXTEND, 0, 0 );
}

void wxScintilla::PageDownRectExtend() {
  SendMsg( SCI_PAGEDOWNRECTEXTEND, 0, 0 );
}

void wxScintilla::StutteredPageUp() {
  SendMsg( SCI_STUTTEREDPAGEUP, 0, 0 );
}

void wxScintilla::StutteredPageUpExtend() {
  SendMsg( SCI_STUTTEREDPAGEUPEXTEND, 0, 0 );
}

void wxScintilla::StutteredPageDown() {
  SendMsg( SCI_STUTTEREDPAGEDOWN, 0, 0 );
}

void wxScintilla::StutteredPageDownExtend() {
  SendMsg( SCI_STUTTEREDPAGEDOWNEXTEND, 0, 0 );
}

void wxScintilla::WordLeftEnd() {
  SendMsg( SCI_WORDLEFTEND, 0, 0 );
}

void wxScintilla::WordLeftEndExtend() {
  SendMsg( SCI_WORDLEFTENDEXTEND, 0, 0 );
}

void wxScintilla::WordRightEnd() {
  SendMsg( SCI_WORDRIGHTEND, 0, 0 );
}

void wxScintilla::WordRightEndExtend() {
  SendMsg( SCI_WORDRIGHTENDEXTEND, 0, 0 );
}


void wxScintilla::SetWhitespaceChars( const wxString& characters ) {
  SendMsg( SCI_SETWHITESPACECHARS, 0, ( uptr_t )( const char* )wx2sci( characters ) );
}


wxString wxScintilla::GetWhitespaceChars() const {
  const int msg = SCI_GETWHITESPACECHARS;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


void wxScintilla::SetPunctuationChars( const wxString& characters ) {
  SendMsg( SCI_SETPUNCTUATIONCHARS, 0, ( sptr_t )( const char* )wx2sci( characters ) );
}


wxString wxScintilla::GetPunctuationChars() const {
  const int msg = SCI_GETPUNCTUATIONCHARS;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::SetCharsDefault() {
  SendMsg( SCI_SETCHARSDEFAULT, 0, 0 );
}


int wxScintilla::AutoCompGetCurrent() const {
  return SendMsg( SCI_AUTOCGETCURRENT, 0, 0 );
}

void wxScintilla::AutoCompSetCaseInsensitiveBehaviour( int behaviour ) {
  SendMsg( SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, behaviour, 0 );
}


int wxScintilla::AutoCompGetCaseInsensitiveBehaviour() const {
  return SendMsg( SCI_AUTOCGETCASEINSENSITIVEBEHAVIOUR, 0, 0 );
}

void wxScintilla::AutoCSetMulti( int multi ) {
  SendMsg( SCI_AUTOCSETMULTI, multi, 0 );
}


int wxScintilla::AutoCGetMulti() const {
  return SendMsg( SCI_AUTOCGETMULTI, 0, 0 );
}

void wxScintilla::AutoCompSetOrder( int order ) {
  SendMsg( SCI_AUTOCSETORDER, order, 0 );
}


int wxScintilla::AutoCompGetOrder() const {
  return SendMsg( SCI_AUTOCGETORDER, 0, 0 );
}



wxString wxScintilla::AutoCompGetCurrentText() const {
  const long len = SendMsg( SCI_AUTOCGETCURRENTTEXT, 0, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 2 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_AUTOCGETCURRENTTEXT, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


void wxScintilla::Allocate( int bytes ) {
  SendMsg( SCI_ALLOCATE, bytes, 0 );
}


int wxScintilla::FindColumn( int line, int column ) {
  return SendMsg( SCI_FINDCOLUMN, line, column );
}


int wxScintilla::GetCaretSticky() const {
  return SendMsg( SCI_GETCARETSTICKY, 0, 0 );
}

void wxScintilla::SetCaretSticky( int useCaretStickyBehaviour ) {
  SendMsg( SCI_SETCARETSTICKY, useCaretStickyBehaviour, 0 );
}

void wxScintilla::ToggleCaretSticky() {
  SendMsg( SCI_TOGGLECARETSTICKY, 0, 0 );
}

void wxScintilla::SetPasteConvertEndings( bool convert ) {
  SendMsg( SCI_SETPASTECONVERTENDINGS, convert, 0 );
}


bool wxScintilla::GetPasteConvertEndings() const {
  return SendMsg( SCI_GETPASTECONVERTENDINGS, 0, 0 ) != 0;
}

void wxScintilla::SelectionDuplicate() {
  SendMsg( SCI_SELECTIONDUPLICATE, 0, 0 );
}

void wxScintilla::SetCaretLineBackAlpha( int alpha ) {
  SendMsg( SCI_SETCARETLINEBACKALPHA, alpha, 0 );
}


int wxScintilla::GetCaretLineBackAlpha() const {
  return SendMsg( SCI_GETCARETLINEBACKALPHA, 0, 0 );
}

void wxScintilla::SetCaretStyle( int caretStyle ) {
  SendMsg( SCI_SETCARETSTYLE, caretStyle, 0 );
}


int wxScintilla::GetCaretStyle() const {
  return SendMsg( SCI_GETCARETSTYLE, 0, 0 );
}

void wxScintilla::SetIndicatorCurrent( int indicator ) {
  SendMsg( SCI_SETINDICATORCURRENT, indicator, 0 );
}


int wxScintilla::GetIndicatorCurrent() const {
  return SendMsg( SCI_GETINDICATORCURRENT, 0, 0 );
}

void wxScintilla::SetIndicatorValue( int value ) {
  SendMsg( SCI_SETINDICATORVALUE, value, 0 );
}


int wxScintilla::GetIndicatorValue() const {
  return SendMsg( SCI_GETINDICATORVALUE, 0, 0 );
}

void wxScintilla::IndicatorFillRange( int position, int fillLength ) {
  SendMsg( SCI_INDICATORFILLRANGE, position, fillLength );
}

void wxScintilla::IndicatorClearRange( int position, int clearLength ) {
  SendMsg( SCI_INDICATORCLEARRANGE, position, clearLength );
}


int wxScintilla::IndicatorAllOnFor( int position ) {
  return SendMsg( SCI_INDICATORALLONFOR, position, 0 );
}


int wxScintilla::IndicatorValueAt( int indicator, int position ) {
  return SendMsg( SCI_INDICATORVALUEAT, indicator, position );
}


int wxScintilla::IndicatorStart( int indicator, int position ) {
  return SendMsg( SCI_INDICATORSTART, indicator, position );
}


int wxScintilla::IndicatorEnd( int indicator, int position ) {
  return SendMsg( SCI_INDICATOREND, indicator, position );
}

void wxScintilla::SetPositionCacheSize( int size ) {
  SendMsg( SCI_SETPOSITIONCACHE, size, 0 );
}


int wxScintilla::GetPositionCacheSize() const {
  return SendMsg( SCI_GETPOSITIONCACHE, 0, 0 );
}

void wxScintilla::CopyAllowLine() {
  SendMsg( SCI_COPYALLOWLINE, 0, 0 );
}







const char* wxScintilla::GetRangePointer( int position, int rangeLength ) const {
  return reinterpret_cast<const char*>( SendMsg( SCI_GETRANGEPOINTER, position, rangeLength ) );
}


int wxScintilla::GetGapPosition() const {
  return SendMsg( SCI_GETGAPPOSITION, 0, 0 );
}

void wxScintilla::SetKeysUnicode( bool keysUnicode ) {
  SendMsg( SCI_SETKEYSUNICODE, keysUnicode, 0 );
}


bool wxScintilla::GetKeysUnicode() const {
  return SendMsg( SCI_GETKEYSUNICODE, 0, 0 ) != 0;
}

void wxScintilla::IndicatorSetAlpha( int indicator, int alpha ) {
  SendMsg( SCI_INDICSETALPHA, indicator, alpha );
}


int wxScintilla::IndicatorGetAlpha( int indicator ) const {
  return SendMsg( SCI_INDICGETALPHA, indicator, 0 );
}

void wxScintilla::IndicatorSetOutlineAlpha( int indicator, int alpha ) {
  SendMsg( SCI_INDICSETOUTLINEALPHA, indicator, alpha );
}


int wxScintilla::IndicatorGetOutlineAlpha( int indicator ) const {
  return SendMsg( SCI_INDICGETOUTLINEALPHA, indicator, 0 );
}

void wxScintilla::SetExtraAscent( int extraAscent ) {
  SendMsg( SCI_SETEXTRAASCENT, extraAscent, 0 );
}


int wxScintilla::GetExtraAscent() const {
  return SendMsg( SCI_GETEXTRAASCENT, 0, 0 );
}

void wxScintilla::SetExtraDescent( int extraDescent ) {
  SendMsg( SCI_SETEXTRADESCENT, extraDescent, 0 );
}


int wxScintilla::GetExtraDescent() const {
  return SendMsg( SCI_GETEXTRADESCENT, 0, 0 );
}


int wxScintilla::GetMarkerSymbolDefined( int markerNumber ) {
  return SendMsg( SCI_MARKERSYMBOLDEFINED, markerNumber, 0 );
}

void wxScintilla::MarginSetText( int line, const wxString& text ) {
  SendMsg( SCI_MARGINSETTEXT, line, ( sptr_t )( const char* )wx2sci( text ) );
}


wxString wxScintilla::MarginGetText( int line ) const {
  const int msg = SCI_MARGINGETTEXT;
  const long len = SendMsg( msg, line, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, line, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::MarginSetStyle( int line, int style ) {
  SendMsg( SCI_MARGINSETSTYLE, line, style );
}


int wxScintilla::MarginGetStyle( int line ) const {
  return SendMsg( SCI_MARGINGETSTYLE, line, 0 );
}

void wxScintilla::MarginSetStyles( int line, const wxString& styles ) {
  SendMsg( SCI_MARGINSETSTYLES, line, ( uptr_t )( const char* )wx2sci( styles ) );
}


wxString wxScintilla::MarginGetStyles( int line ) const {
  const int msg = SCI_MARGINGETSTYLES;
  const long len = SendMsg( msg, line, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, line, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::MarginTextClearAll() {
  SendMsg( SCI_MARGINTEXTCLEARALL, 0, 0 );
}

void wxScintilla::MarginSetStyleOffset( int style ) {
  SendMsg( SCI_MARGINSETSTYLEOFFSET, style, 0 );
}


int wxScintilla::MarginGetStyleOffset() const {
  return SendMsg( SCI_MARGINGETSTYLEOFFSET, 0, 0 );
}

void wxScintilla::SetMarginOptions( int marginOptions ) {
  SendMsg( SCI_SETMARGINOPTIONS, marginOptions, 0 );
}


int wxScintilla::GetMarginOptions() const {
  return SendMsg( SCI_GETMARGINOPTIONS, 0, 0 );
}

void wxScintilla::AnnotationSetText( int line, const wxString& text ) {
  SendMsg( SCI_ANNOTATIONSETTEXT, line, ( uptr_t )( const char* )wx2sci( text ) );
}


wxString wxScintilla::AnnotationGetText( int line ) const {
  const int msg = SCI_ANNOTATIONGETTEXT;
  const long len = SendMsg( msg, line, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, line, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::AnnotationSetStyle( int line, int style ) {
  SendMsg( SCI_ANNOTATIONSETSTYLE, line, style );
}


int wxScintilla::AnnotationGetStyle( int line ) const {
  return SendMsg( SCI_ANNOTATIONGETSTYLE, line, 0 );
}

void wxScintilla::AnnotationSetStyles( int line, const wxString& styles ) {
  SendMsg( SCI_ANNOTATIONSETSTYLES, line, ( uptr_t )( const char* )wx2sci( styles ) );
}


wxString wxScintilla::AnnotationGetStyles( int line ) const {
  const int msg = SCI_ANNOTATIONGETSTYLES;
  const long len = SendMsg( msg, line, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, line, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


int wxScintilla::AnnotationGetLines( int line ) const {
  return SendMsg( SCI_ANNOTATIONGETLINES, line, 0 );
}

void wxScintilla::AnnotationClearAll() {
  SendMsg( SCI_ANNOTATIONCLEARALL, 0, 0 );
}

void wxScintilla::AnnotationSetVisible( int visible ) {
  SendMsg( SCI_ANNOTATIONSETVISIBLE, visible, 0 );
}


int wxScintilla::AnnotationGetVisible() const {
  return SendMsg( SCI_ANNOTATIONGETVISIBLE, 0, 0 );
}

void wxScintilla::AnnotationSetStyleOffset( int style ) {
  SendMsg( SCI_ANNOTATIONSETSTYLEOFFSET, style, 0 );
}


int wxScintilla::AnnotationGetStyleOffset() const {
  return SendMsg( SCI_ANNOTATIONGETSTYLEOFFSET, 0, 0 );
}

void wxScintilla::ReleaseAllExtendedStyles() {
  SendMsg( SCI_RELEASEALLEXTENDEDSTYLES, 0, 0 );
}


int wxScintilla::AllocateExtendedStyles( int numberStyles ) {
  return SendMsg( SCI_ALLOCATEEXTENDEDSTYLES, numberStyles, 0 );
}

void wxScintilla::AddUndoAction( int token, int flags ) {
  SendMsg( SCI_ADDUNDOACTION, token, flags );
}


int wxScintilla::CharPositionFromPoint( int x, int y ) {
  return SendMsg( SCI_CHARPOSITIONFROMPOINT, x, y );
}


int wxScintilla::CharPositionFromPointClose( int x, int y ) {
  return SendMsg( SCI_CHARPOSITIONFROMPOINTCLOSE, x, y );
}

void wxScintilla::SetMouseSelectionRectangularSwitch( bool mouseSelectionRectangularSwitch ) {
  SendMsg( SCI_SETMOUSESELECTIONRECTANGULARSWITCH, mouseSelectionRectangularSwitch, 0 );
}


bool wxScintilla::GetMouseSelectionRectangularSwitch() const {
  return SendMsg( SCI_GETMOUSESELECTIONRECTANGULARSWITCH, 0, 0 ) != 0;
}

void wxScintilla::SetMultipleSelection( bool multipleSelection ) {
  SendMsg( SCI_SETMULTIPLESELECTION, multipleSelection, 0 );
}


bool wxScintilla::GetMultipleSelection() const {
  return SendMsg( SCI_GETMULTIPLESELECTION, 0, 0 ) != 0;
}

void wxScintilla::SetAdditionalSelectionTyping( bool additionalSelectionTyping ) {
  SendMsg( SCI_SETADDITIONALSELECTIONTYPING, additionalSelectionTyping, 0 );
}


bool wxScintilla::GetAdditionalSelectionTyping() const {
  return SendMsg( SCI_GETADDITIONALSELECTIONTYPING, 0, 0 ) != 0;
}

void wxScintilla::SetAdditionalCaretsBlink( bool additionalCaretsBlink ) {
  SendMsg( SCI_SETADDITIONALCARETSBLINK, additionalCaretsBlink, 0 );
}


bool wxScintilla::GetAdditionalCaretsBlink() const {
  return SendMsg( SCI_GETADDITIONALCARETSBLINK, 0, 0 ) != 0;
}

void wxScintilla::SetAdditionalCaretsVisible( bool additionalCaretsBlink ) {
  SendMsg( SCI_SETADDITIONALCARETSVISIBLE, additionalCaretsBlink, 0 );
}


bool wxScintilla::GetAdditionalCaretsVisible() const {
  return SendMsg( SCI_GETADDITIONALCARETSVISIBLE, 0, 0 ) != 0;
}


int wxScintilla::GetSelections() const {
  return SendMsg( SCI_GETSELECTIONS, 0, 0 );
}


bool wxScintilla::GetSelectionEmpty() const {
  return SendMsg( SCI_GETSELECTIONEMPTY, 0, 0 ) != 0;
}

void wxScintilla::ClearSelections() {
  SendMsg( SCI_CLEARSELECTIONS, 0, 0 );
}


void wxScintilla::SetSelectionVoid( int startPos, int endPos ) {
  SendMsg( SCI_SETSEL, startPos, endPos );
}


int wxScintilla::SetSelectionInt( int caret, int anchor ) {
  return SendMsg( SCI_SETSELECTION, caret, anchor );
}



int wxScintilla::AddSelection( int caret, int anchor ) {
  return SendMsg( SCI_ADDSELECTION, caret, anchor );
}

void wxScintilla::DropSelectionN( int selection ) {
  SendMsg( SCI_DROPSELECTIONN, selection, 0 );
}

void wxScintilla::SetMainSelection( int selection ) {
  SendMsg( SCI_SETMAINSELECTION, selection, 0 );
}


int wxScintilla::GetMainSelection() const {
  return SendMsg( SCI_GETMAINSELECTION, 0, 0 );
}

void wxScintilla::SetSelectionNCaret( int selection, int pos ) {
  SendMsg( SCI_SETSELECTIONNCARET, selection, pos );
}
int wxScintilla::GetSelectionNCaret( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNCARET, selection, 0 );
}

void wxScintilla::SetSelectionNAnchor( int selection, int posAnchor ) {
  SendMsg( SCI_SETSELECTIONNANCHOR, selection, posAnchor );
}
int wxScintilla::GetSelectionNAnchor( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNANCHOR, selection, 0 );
}

void wxScintilla::SetSelectionNCaretVirtualSpace( int selection, int space ) {
  SendMsg( SCI_SETSELECTIONNCARETVIRTUALSPACE, selection, space );
}
int wxScintilla::GetSelectionNCaretVirtualSpace( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNCARETVIRTUALSPACE, selection, 0 );
}

void wxScintilla::SetSelectionNAnchorVirtualSpace( int selection, int space ) {
  SendMsg( SCI_SETSELECTIONNANCHORVIRTUALSPACE, selection, space );
}
int wxScintilla::GetSelectionNAnchorVirtualSpace( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNANCHORVIRTUALSPACE, selection, 0 );
}

void wxScintilla::SetSelectionNStart( int selection, int pos ) {
  SendMsg( SCI_SETSELECTIONNSTART, selection, pos );
}


int wxScintilla::GetSelectionNStart( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNSTART, selection, 0 );
}

void wxScintilla::SetSelectionNEnd( int selection, int pos ) {
  SendMsg( SCI_SETSELECTIONNEND, selection, pos );
}


int wxScintilla::GetSelectionNEnd( int selection ) const {
  return SendMsg( SCI_GETSELECTIONNEND, selection, 0 );
}

void wxScintilla::SetRectangularSelectionCaret( int pos ) {
  SendMsg( SCI_SETRECTANGULARSELECTIONCARET, pos, 0 );
}
int wxScintilla::GetRectangularSelectionCaret() const {
  return SendMsg( SCI_GETRECTANGULARSELECTIONCARET, 0, 0 );
}

void wxScintilla::SetRectangularSelectionAnchor( int posAnchor ) {
  SendMsg( SCI_SETRECTANGULARSELECTIONANCHOR, posAnchor, 0 );
}
int wxScintilla::GetRectangularSelectionAnchor() const {
  return SendMsg( SCI_GETRECTANGULARSELECTIONANCHOR, 0, 0 );
}

void wxScintilla::SetRectangularSelectionCaretVirtualSpace( int space ) {
  SendMsg( SCI_SETRECTANGULARSELECTIONCARETVIRTUALSPACE, space, 0 );
}
int wxScintilla::GetRectangularSelectionCaretVirtualSpace() const {
  return SendMsg( SCI_GETRECTANGULARSELECTIONCARETVIRTUALSPACE, 0, 0 );
}

void wxScintilla::SetRectangularSelectionAnchorVirtualSpace( int space ) {
  SendMsg( SCI_SETRECTANGULARSELECTIONANCHORVIRTUALSPACE, space, 0 );
}
int wxScintilla::GetRectangularSelectionAnchorVirtualSpace() const {
  return SendMsg( SCI_GETRECTANGULARSELECTIONANCHORVIRTUALSPACE, 0, 0 );
}

void wxScintilla::SetVirtualSpaceOptions( int virtualSpaceOptions ) {
  SendMsg( SCI_SETVIRTUALSPACEOPTIONS, virtualSpaceOptions, 0 );
}
int wxScintilla::GetVirtualSpaceOptions() const {
  return SendMsg( SCI_GETVIRTUALSPACEOPTIONS, 0, 0 );
}


void wxScintilla::SetRectangularSelectionModifier( int modifier ) {
  SendMsg( SCI_SETRECTANGULARSELECTIONMODIFIER, modifier, 0 );
}


int wxScintilla::GetRectangularSelectionModifier() const {
  return SendMsg( SCI_GETRECTANGULARSELECTIONMODIFIER, 0, 0 );
}


void wxScintilla::SetAdditionalSelForeground( const wxColour& fore ) {
  SendMsg( SCI_SETADDITIONALSELFORE, wxColourAsLong( fore ), 0 );
}


void wxScintilla::SetAdditionalSelBackground( const wxColour& back ) {
  SendMsg( SCI_SETADDITIONALSELBACK, wxColourAsLong( back ), 0 );
}

void wxScintilla::SetAdditionalSelAlpha( int alpha ) {
  SendMsg( SCI_SETADDITIONALSELALPHA, alpha, 0 );
}


int wxScintilla::GetAdditionalSelAlpha() const {
  return SendMsg( SCI_GETADDITIONALSELALPHA, 0, 0 );
}

void wxScintilla::SetAdditionalCaretForeground( const wxColour& fore ) {
  SendMsg( SCI_SETADDITIONALCARETFORE, wxColourAsLong( fore ), 0 );
}


wxColour wxScintilla::GetAdditionalCaretForeground() const {
  long c = SendMsg( SCI_GETADDITIONALCARETFORE, 0, 0 );
  return wxColourFromLong( c );
}

void wxScintilla::RotateSelection() {
  SendMsg( SCI_ROTATESELECTION, 0, 0 );
}

void wxScintilla::SwapMainAnchorCaret() {
  SendMsg( SCI_SWAPMAINANCHORCARET, 0, 0 );
}


int wxScintilla::ChangeLexerState( int start, int end ) {
  return SendMsg( SCI_CHANGELEXERSTATE, start, end );
}


int wxScintilla::ContractedFoldNext( int lineStart ) {
  return SendMsg( SCI_CONTRACTEDFOLDNEXT, lineStart, 0 );
}

void wxScintilla::VerticalCentreCaret() {
  SendMsg( SCI_VERTICALCENTRECARET, 0, 0 );
}

void wxScintilla::MoveSelectedLinesUp() {
  SendMsg( SCI_MOVESELECTEDLINESUP, 0, 0 );
}

void wxScintilla::MoveSelectedLinesDown() {
  SendMsg( SCI_MOVESELECTEDLINESDOWN, 0, 0 );
}

void wxScintilla::SetIdentifier( int identifier ) {
  SendMsg( SCI_SETIDENTIFIER, identifier, 0 );
}


int wxScintilla::GetIdentifier() const {
  return SendMsg( SCI_GETIDENTIFIER, 0, 0 );
}

void wxScintilla::RGBAImageSetWidth( int width ) {
  SendMsg( SCI_RGBAIMAGESETWIDTH, width, 0 );
}

void wxScintilla::RGBAImageSetHeight( int height ) {
  SendMsg( SCI_RGBAIMAGESETHEIGHT, height, 0 );
}

void wxScintilla::RGBAImageSetScale( int scalePercent ) {
  SendMsg( SCI_RGBAIMAGESETSCALE, scalePercent, 0 );
}


void wxScintilla::MarkerDefineRGBAImage( int markerNumber, const unsigned char* pixels ) {
  SendMsg( SCI_MARKERDEFINERGBAIMAGE, markerNumber, ( uptr_t )pixels );
}


void wxScintilla::RegisterRGBAImage( int type, const unsigned char* pixels ) {
  SendMsg( SCI_REGISTERRGBAIMAGE, type, ( uptr_t )pixels );
}

void wxScintilla::ScrollToStart() {
  SendMsg( SCI_SCROLLTOSTART, 0, 0 );
}

void wxScintilla::ScrollToEnd() {
  SendMsg( SCI_SCROLLTOEND, 0, 0 );
}

void wxScintilla::SetTechnology( int technology ) {
  SendMsg( SCI_SETTECHNOLOGY, technology, 0 );
}


int wxScintilla::GetTechnology() const {
  return SendMsg( SCI_GETTECHNOLOGY, 0, 0 );
}

void* wxScintilla::CreateLoader( int bytes ) const {
  return reinterpret_cast<void*>( SendMsg( SCI_CREATELOADER, bytes, 0 ) );
}


void wxScintilla::VCHomeDisplay() {
  SendMsg( SCI_VCHOMEDISPLAY, 0, 0 );
}

void wxScintilla::VCHomeDisplayExtend() {
  SendMsg( SCI_VCHOMEDISPLAYEXTEND, 0, 0 );
}


bool wxScintilla::GetCaretLineVisibleAlways() const {
  return SendMsg( SCI_GETCARETLINEVISIBLEALWAYS, 0, 0 ) != 0;
}

void wxScintilla::SetCaretLineVisibleAlways( bool alwaysVisible ) {
  SendMsg( SCI_SETCARETLINEVISIBLEALWAYS, alwaysVisible, 0 );
}

void wxScintilla::SetLineEndTypesAllowed( int lineEndBitSet ) {
  SendMsg( SCI_SETLINEENDTYPESALLOWED, lineEndBitSet, 0 );
}


int wxScintilla::GetLineEndTypesAllowed() const {
  return SendMsg( SCI_GETLINEENDTYPESALLOWED, 0, 0 );
}


int wxScintilla::GetLineEndTypesActive() const {
  return SendMsg( SCI_GETLINEENDTYPESACTIVE, 0, 0 );
}

void wxScintilla::SetRepresentation( const wxString& encodedCharacter, const wxString& representation ) {
  SendMsg( SCI_SETREPRESENTATION, ( sptr_t )( const char* )wx2sci( encodedCharacter ), ( sptr_t )( const char* )wx2sci( representation ) );
}


wxString wxScintilla::GetRepresentation( const wxString& encodedCharacter ) const

{
  const int msg = SCI_GETREPRESENTATION;
  const long len = SendMsg( msg, ( sptr_t )( const char* )wx2sci( encodedCharacter ), ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, ( sptr_t )( const char* )wx2sci( encodedCharacter ), ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

void wxScintilla::ClearRepresentation( const wxString& encodedCharacter ) {
  SendMsg( SCI_CLEARREPRESENTATION, ( sptr_t )( const char* )wx2sci( encodedCharacter ), 0 );
}


void wxScintilla::FindIndicatorShow( int start, int end ) {
  SendMsg( SCI_FINDINDICATORSHOW, start, end );
}

void wxScintilla::FindIndicatorFlash( int start, int end ) {
  SendMsg( SCI_FINDINDICATORFLASH, start, end );
}

void wxScintilla::FindIndicatorHide() {
  SendMsg( SCI_FINDINDICATORHIDE, 0, 0 );
}


void wxScintilla::StartRecord() {
  SendMsg( SCI_STARTRECORD, 0, 0 );
}

void wxScintilla::StopRecord() {
  SendMsg( SCI_STOPRECORD, 0, 0 );
}

void wxScintilla::SetLexer( int lexer ) {
  SendMsg( SCI_SETLEXER, lexer, 0 );
}


int wxScintilla::GetLexer() const {
  return SendMsg( SCI_GETLEXER, 0, 0 );
}

void wxScintilla::Colourise( int start, int end ) {
  SendMsg( SCI_COLOURISE, start, end );
}

void wxScintilla::SetProperty( const wxString& key, const wxString& value ) {
  SendMsg( SCI_SETPROPERTY, ( sptr_t )( const char* )wx2sci( key ), ( uptr_t )( const char* )wx2sci( value ) );
}

void wxScintilla::SetKeyWords( int keywordSet, const wxString& keyWords ) {
  SendMsg( SCI_SETKEYWORDS, keywordSet, ( uptr_t )( const char* )wx2sci( keyWords ) );
}

void wxScintilla::SetLexerLanguage( const wxString& language ) {
  SendMsg( SCI_SETLEXERLANGUAGE, 0, ( uptr_t )( const char* )wx2sci( language ) );
}


wxString wxScintilla::GetProperty( const wxString& key ) {
  const long len = SendMsg( SCI_GETPROPERTY, ( sptr_t )( const char* )wx2sci( key ), 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETPROPERTY, ( sptr_t )( const char* )wx2sci( key ), ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


wxString wxScintilla::GetPropertyExpanded( const wxString& key ) {
  const long len = SendMsg( SCI_GETPROPERTYEXPANDED, ( sptr_t )( const char* )wx2sci( key ), 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETPROPERTYEXPANDED, ( sptr_t )( const char* )wx2sci( key ), ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


int wxScintilla::GetPropertyInt( const wxString& key ) const {
  return SendMsg( SCI_GETPROPERTYINT, ( sptr_t )( const char* )wx2sci( key ), 0 );
}


int wxScintilla::GetStyleBitsNeeded() const {
  return SendMsg( SCI_GETSTYLEBITSNEEDED, 0, 0 );
}

void* wxScintilla::PrivateLexerCall( int operation, void* pointer ) {
  return reinterpret_cast<void*>( SendMsg( SCI_PRIVATELEXERCALL, operation, ( uptr_t )pointer ) );
}


wxString wxScintilla::PropertyNames() const {
  const int msg = SCI_PROPERTYNAMES;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


int wxScintilla::PropertyType( const wxString& name ) {
  return SendMsg( SCI_PROPERTYTYPE, ( sptr_t )( const char* )wx2sci( name ), 0 );
}


wxString wxScintilla::DescribeProperty( const wxString& name ) const {
  const int msg = SCI_DESCRIBEPROPERTY;
  const long len = SendMsg( msg, ( sptr_t )( const char* )wx2sci( name ), ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, ( sptr_t )( const char* )wx2sci( name ), ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}


wxString wxScintilla::DescribeKeyWordSets() const {
  const int msg = SCI_DESCRIBEKEYWORDSETS;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

int wxScintilla::GetLineEndTypesSupported() const {
  return SendMsg( SCI_GETLINEENDTYPESSUPPORTED, 0, 0 );
}


int wxScintilla::AllocateSubStyles( int styleBase, int numberStyles ) {
  return SendMsg( SCI_ALLOCATESUBSTYLES, styleBase, numberStyles );
}


int wxScintilla::GetSubStylesStart( int styleBase ) const {
  return SendMsg( SCI_GETSUBSTYLESSTART, styleBase, 0 );
}


int wxScintilla::GetSubStylesLength( int styleBase ) const {
  return SendMsg( SCI_GETSUBSTYLESLENGTH, styleBase, 0 );
}


int wxScintilla::GetStyleFromSubStyle( int subStyle ) const {
  return SendMsg( SCI_GETSTYLEFROMSUBSTYLE, subStyle, 0 );
}


int wxScintilla::GetPrimaryStyleFromStyle( int style ) const {
  return SendMsg( SCI_GETPRIMARYSTYLEFROMSTYLE, style, 0 );
}

void wxScintilla::FreeSubStyles() {
  SendMsg( SCI_FREESUBSTYLES, 0, 0 );
}

void wxScintilla::SetIdentifiers( int style, const wxString& identifiers ) {
  SendMsg( SCI_SETIDENTIFIERS, style, ( sptr_t )( const char* )wx2sci( identifiers ) );
}


int wxScintilla::DistanceToSecondaryStyles() const {
  return SendMsg( SCI_DISTANCETOSECONDARYSTYLES, 0, 0 );
}


wxString wxScintilla::GetSubStyleBases() const {
  const int msg = SCI_GETSUBSTYLEBASES;
  const long len = SendMsg( msg, 0, ( uptr_t )NULL );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 1 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( msg, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

wxSciFnDirect wxScintilla::GetDirectFunction() {
  return ( wxSciFnDirect )SendMsg( SCI_GETDIRECTFUNCTION, 0, 0 );
}

wxIntPtr wxScintilla::GetDirectPointer() const {
  return ( wxIntPtr )SendMsg( SCI_GETDIRECTPOINTER, 0, 0 );
}

wxUIntPtr wxScintilla::GetCharacterPointer() const {
  return ( wxUIntPtr )SendMsg( SCI_GETCHARACTERPOINTER, 0, 0 );
}

void wxScintilla::GrabSCIFocus() {
  SendMsg( SCI_GRABFOCUS, 0, 0 );
}

void wxScintilla::LoadLexerLibrary( const wxString& path ) {
  SendMsg( SCI_LOADLEXERLIBRARY, 0, ( uptr_t )( const char* )wx2sci( path ) );
}

wxString wxScintilla::GetLexerLanguage() const {
  const long len = SendMsg( SCI_GETLEXERLANGUAGE, 0, 0 );
  if( !len ) {
    return wxEmptyString;
  }
  wxMemoryBuffer mbuf( len + 2 );
  char* buf = ( char* )mbuf.GetWriteBuf( len + 1 );
  SendMsg( SCI_GETLEXERLANGUAGE, 0, ( uptr_t )buf );
  mbuf.UngetWriteBuf( len );
  mbuf.AppendByte( 0 );
  return sci2wx( buf );
}

int wxScintilla::GetCurrentLine() {
  int line = LineFromPosition( GetCurrentPos() );
  return line;
}

void wxScintilla::StyleSetSpec( int styleNum, const wxString& spec ) {
  wxStringTokenizer tkz( spec, _T( "," ) );
  while( tkz.HasMoreTokens() ) {
    wxString token = tkz.GetNextToken();
    wxString option = token.BeforeFirst( ':' );
    wxString val = token.AfterFirst( ':' );
    if( option == _T( "bold" ) ) {
      StyleSetBold( styleNum, true );
    } else if( option == _T( "italic" ) ) {
      StyleSetItalic( styleNum, true );
    } else if( option == _T( "underline" ) ) {
      StyleSetUnderline( styleNum, true );
    } else if( option == _T( "eol" ) ) {
      StyleSetEOLFilled( styleNum, true );
    } else if( option == _T( "size" ) ) {
      long points;
      if( val.ToLong( &points ) ) {
        StyleSetSize( styleNum, points );
      }
    } else if( option == _T( "face" ) ) {
      StyleSetFaceName( styleNum, val );
    } else if( option == _T( "fore" ) ) {
      StyleSetForeground( styleNum, wxColourFromSpec( val ) );
    } else if( option == _T( "back" ) ) {
      StyleSetBackground( styleNum, wxColourFromSpec( val ) );
    }
  }
}



wxFont wxScintilla::StyleGetFont( int style ) {
  wxFont font;
  font.SetPointSize( StyleGetSize( style ) );
  font.SetFaceName( StyleGetFaceName( style ) );
  if( StyleGetBold( style ) ) {
    font.SetWeight( wxFONTWEIGHT_BOLD );
  } else {
    font.SetWeight( wxFONTWEIGHT_NORMAL );
  }
  if( StyleGetItalic( style ) ) {
    font.SetStyle( wxFONTSTYLE_ITALIC );
  } else {
    font.SetStyle( wxFONTSTYLE_NORMAL );
  }
  return font;
}



void wxScintilla::StyleSetFont( int styleNum, wxFont& font ) {
  int x, y;
  GetTextExtent( _T( "X" ), &x, &y, NULL, NULL, &font );
  int size = font.GetPointSize();
  wxString faceName = font.GetFaceName();
  bool bold = font.GetWeight() == wxFONTWEIGHT_BOLD;
  bool italic = font.GetStyle() == wxFONTSTYLE_ITALIC;
  bool under = font.GetUnderlined();
  wxFontEncoding encoding = font.GetEncoding();
  StyleSetFontAttr( styleNum, size, faceName, bold, italic, under, encoding );
}

void wxScintilla::StyleSetFontAttr( int styleNum, int size, const wxString& faceName, bool bold, bool italic, bool underline, wxFontEncoding encoding ) {
  StyleSetSize( styleNum, size );
  StyleSetFaceName( styleNum, faceName );
  StyleSetBold( styleNum, bold );
  StyleSetItalic( styleNum, italic );
  StyleSetUnderline( styleNum, underline );
  StyleSetFontEncoding( styleNum, encoding );
}



void wxScintilla::StyleSetCharacterSet( int style, int characterSet ) {
  wxFontEncoding encoding;
  switch( characterSet ) {
    default:
    case wxSCI_CHARSET_ANSI:
    case wxSCI_CHARSET_DEFAULT:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_BALTIC:
      encoding = wxFONTENCODING_ISO8859_13;
      break;
    case wxSCI_CHARSET_CHINESEBIG5:
      encoding = wxFONTENCODING_CP950;
      break;
    case wxSCI_CHARSET_EASTEUROPE:
      encoding = wxFONTENCODING_ISO8859_2;
      break;
    case wxSCI_CHARSET_GB2312:
      encoding = wxFONTENCODING_CP936;
      break;
    case wxSCI_CHARSET_GREEK:
      encoding = wxFONTENCODING_ISO8859_7;
      break;
    case wxSCI_CHARSET_HANGUL:
      encoding = wxFONTENCODING_CP949;
      break;
    case wxSCI_CHARSET_MAC:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_OEM:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_RUSSIAN:
      encoding = wxFONTENCODING_KOI8;
      break;
    case wxSCI_CHARSET_SHIFTJIS:
      encoding = wxFONTENCODING_CP932;
      break;
    case wxSCI_CHARSET_SYMBOL:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_TURKISH:
      encoding = wxFONTENCODING_ISO8859_9;
      break;
    case wxSCI_CHARSET_JOHAB:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_HEBREW:
      encoding = wxFONTENCODING_ISO8859_8;
      break;
    case wxSCI_CHARSET_ARABIC:
      encoding = wxFONTENCODING_ISO8859_6;
      break;
    case wxSCI_CHARSET_VIETNAMESE:
      encoding = wxFONTENCODING_DEFAULT;
      break;
    case wxSCI_CHARSET_THAI:
      encoding = wxFONTENCODING_ISO8859_11;
      break;
    case wxSCI_CHARSET_CYRILLIC:
      encoding = wxFONTENCODING_ISO8859_5;
      break;
    case wxSCI_CHARSET_8859_15:
      encoding = wxFONTENCODING_ISO8859_15;
      break;
  }
  SendMsg( SCI_STYLESETCHARACTERSET, style, encoding + 1 );
}


void wxScintilla::StyleSetFontEncoding( int style, wxFontEncoding encoding ) {
  SendMsg( SCI_STYLESETCHARACTERSET, style, encoding + 1 );
}


void wxScintilla::CmdKeyExecute( int cmd ) {
  SendMsg( cmd );
}


void wxScintilla::SetMargins( int left, int right ) {
  SetMarginLeft( left );
  SetMarginRight( right );
}



wxPoint wxScintilla::PointFromPosition( int pos ) {
  int x = SendMsg( SCI_POINTXFROMPOSITION, 0, pos );
  int y = SendMsg( SCI_POINTYFROMPOSITION, 0, pos );
  return wxPoint( x, y );
}

void wxScintilla::ScrollToLine( int line ) {
  m_swx->DoScrollToLine( line );
}


void wxScintilla::ScrollToColumn( int column ) {
  m_swx->DoScrollToColumn( column );
}



void wxScintilla::DoSetValue( const wxString& value, int ) {
  SetText( value );
}

bool wxScintilla::DoSaveFile( const wxString& filename, int ( fileType ) ) {
  #if wxUSE_FFILE || wxUSE_FILE
  #if wxUSE_FFILE
  wxFFile file( filename, _T( "wb" ) );
  #elif wxUSE_FILE
  wxFile file( filename, wxFile::write );
  #endif
  if( file.IsOpened() && file.Write( GetValue(), *wxConvCurrent ) ) {
    SetSavePoint();
    return true;
  }
  #endif
  return false;
}


bool wxScintilla::DoLoadFile( const wxString& filename, int ( fileType ) ) {
  #if wxUSE_FFILE || wxUSE_FILE
  bool ok = false;
  #if wxUSE_FFILE
  wxFFile file( filename, _T( "rb" ) );
  #else
  wxFile file( filename );
  #endif
  if( file.IsOpened() ) {
    wxString text;
    #if wxUSE_FFILE
    ok = file.ReadAll( &text, *wxConvCurrent );
    #else
    ssize_t len = ( ssize_t )file.Length();
    if( len > 0 ) {
      wxMemoryBuffer buffer( len + 1 );
      ok = ( file.Read( buffer.GetData(), len ) == len );
      if( ok ) {
        ( ( char* )buffer.GetData() )[len] = 0;
        text = wxString( buffer, *wxConvCurrent, len );
      }
      const wxString::size_type posLF = text.find( '\n' );
      if( posLF != wxString::npos ) {
        if( posLF > 0 && text[posLF - 1] == '\r' ) {
          SetEOLMode( wxSCI_EOL_CRLF );
        } else
        { SetEOLMode( wxSCI_EOL_LF ); }
      }
    } else {
      if( len == 0 ) {
        ok = true;
      } else
      { ok = false; }
    }
    #endif
    if( ok ) {
      SetValue( text );
      EmptyUndoBuffer();
      SetSavePoint();
      return true;
    }
  }
  #endif
  return false;
}

bool wxScintilla::SaveFile( const wxString& filename ) {
  if( filename.empty() ) {
    return false;
  }
  return DoSaveFile( filename, wxTEXT_TYPE_ANY );
}

bool wxScintilla::LoadFile( const wxString& filename ) {
  if( filename.empty() ) {
    return false;
  }
  return DoLoadFile( filename, wxTEXT_TYPE_ANY );
}

#if wxUSE_DRAG_AND_DROP
wxDragResult wxScintilla::DoDragEnter( wxCoord x, wxCoord y, wxDragResult def ) {
  return m_swx->DoDragEnter( x, y, def );
}

wxDragResult wxScintilla::DoDragOver( wxCoord x, wxCoord y, wxDragResult def ) {
  return m_swx->DoDragOver( x, y, def );
}

void wxScintilla::DoDragLeave() {
  m_swx->DoDragLeave();
}

bool wxScintilla::DoDropText( long x, long y, const wxString& data ) {
  return m_swx->DoDropText( x, y, data );
}
#endif


void wxScintilla::SetUseAntiAliasing( bool useAA ) {
  m_swx->SetUseAntiAliasing( useAA );
}

bool wxScintilla::GetUseAntiAliasing() {
  return m_swx->GetUseAntiAliasing();
}

void wxScintilla::AnnotationClearLine( int line ) {
  SendMsg( SCI_ANNOTATIONSETTEXT, line, ( uptr_t )NULL );
}




void wxScintilla::AddTextRaw( const char* text, int length ) {
  if( length == -1 ) {
    length = strlen( text );
  }
  SendMsg( SCI_ADDTEXT, length, ( uptr_t )text );
}

void wxScintilla::InsertTextRaw( int pos, const char* text ) {
  SendMsg( SCI_INSERTTEXT, pos, ( uptr_t )text );
}

wxCharBuffer wxScintilla::GetCurLineRaw( int* linePos ) {
  int len = LineLength( GetCurrentLine() );
  if( !len ) {
    if( linePos ) {
      *linePos = 0;
    }
    wxCharBuffer empty;
    return empty;
  }
  wxCharBuffer buf( len );
  int pos = SendMsg( SCI_GETCURLINE, len, ( uptr_t )buf.data() );
  if( linePos ) {
    *linePos = pos;
  }
  return buf;
}

wxCharBuffer wxScintilla::GetLineRaw( int line ) {
  int len = LineLength( line );
  if( !len ) {
    wxCharBuffer empty;
    return empty;
  }
  wxCharBuffer buf( len );
  SendMsg( SCI_GETLINE, line, ( uptr_t )buf.data() );
  return buf;
}

wxCharBuffer wxScintilla::GetSelectedTextRaw() {
  const long len = SendMsg( SCI_GETSELTEXT, 0, ( uptr_t )0 );
  if( !len ) {
    wxCharBuffer empty;
    return empty;
  }
  wxCharBuffer buf( len );
  SendMsg( SCI_GETSELTEXT, 0, ( uptr_t )buf.data() );
  return buf;
}

wxCharBuffer wxScintilla::GetTextRangeRaw( int startPos, int endPos ) {
  if( endPos < startPos ) {
    int temp = startPos;
    startPos = endPos;
    endPos = temp;
  }
  int len  = endPos - startPos;
  if( !len ) {
    wxCharBuffer empty;
    return empty;
  }
  wxCharBuffer buf( len );
  TextRange tr;
  tr.lpstrText = buf.data();
  tr.chrg.cpMin = startPos;
  tr.chrg.cpMax = endPos;
  SendMsg( SCI_GETTEXTRANGE, 0, ( uptr_t )&tr );
  return buf;
}

void wxScintilla::SetTextRaw( const char* text ) {
  SendMsg( SCI_SETTEXT, 0, ( uptr_t )text );
}

wxCharBuffer wxScintilla::GetTextRaw() {
  int len = GetTextLength();
  wxCharBuffer buf( len );
  SendMsg( SCI_GETTEXT, len + 1, ( uptr_t )buf.data() );
  return buf;
}

void wxScintilla::AppendTextRaw( const char* text, int length ) {
  if( length == -1 ) {
    length = strlen( text );
  }
  SendMsg( SCI_APPENDTEXT, length, ( uptr_t )text );
}


void wxScintilla::SetMouseCapture( bool on ) {
  m_swx->SetMouseCapture( on );
}

bool wxScintilla::HaveMouseCapture() const {
  return m_swx->HaveMouseCapture();
}







void wxScintilla::OnPaint( wxPaintEvent& ( evt ) ) {
  wxBufferedPaintDC dc( this );
  m_swx->DoPaint( &dc, GetUpdateRegion().GetBox() );
}

void wxScintilla::OnScrollWin( wxScrollWinEvent& evt ) {
  if( evt.GetOrientation() == wxHORIZONTAL ) {
    m_swx->DoHScroll( evt.GetEventType(), evt.GetPosition() );
  } else {
    m_swx->DoVScroll( evt.GetEventType(), evt.GetPosition() );
  }
}

void wxScintilla::OnScroll( wxScrollEvent& evt ) {
  wxScrollBar* sb = wxDynamicCast( evt.GetEventObject(), wxScrollBar );
  if( sb ) {
    if( sb->IsVertical() ) {
      m_swx->DoVScroll( evt.GetEventType(), evt.GetPosition() );
    } else
    { m_swx->DoHScroll( evt.GetEventType(), evt.GetPosition() ); }
  }
}

void wxScintilla::OnSize( wxSizeEvent& ( evt ) ) {
  if( m_swx ) {
    wxSize sz = GetClientSize();
    m_swx->DoSize( sz.x, sz.y );
    #if defined(__WXX11__)
    PositionScrollbars();
    #endif
  }
}

void wxScintilla::OnMouseLeftDown( wxMouseEvent& evt ) {
  SetFocus();
  wxPoint pt = evt.GetPosition();
  m_swx->DoLeftButtonDown( Point( pt.x, pt.y ), m_stopWatch.Time(),
                           evt.ShiftDown(), evt.ControlDown(), evt.AltDown() );
}

void wxScintilla::OnMouseMove( wxMouseEvent& evt ) {
  wxPoint pt = evt.GetPosition();
  m_swx->DoLeftButtonMove( Point( pt.x, pt.y ) );
}

void wxScintilla::OnMouseLeftUp( wxMouseEvent& evt ) {
  wxPoint pt = evt.GetPosition();
  m_swx->DoLeftButtonUp( Point( pt.x, pt.y ), m_stopWatch.Time(),
                         evt.ControlDown() );
}


void wxScintilla::OnMouseRightUp( wxMouseEvent& evt ) {
  wxPoint pt = evt.GetPosition();
  m_swx->DoContextMenu( Point( pt.x, pt.y ) );
}


void wxScintilla::OnMouseMiddleUp( wxMouseEvent& evt ) {
  wxPoint pt = evt.GetPosition();
  m_swx->DoMiddleButtonUp( Point( pt.x, pt.y ) );
}

void wxScintilla::OnContextMenu( wxContextMenuEvent& evt ) {
  wxPoint pt = evt.GetPosition();
  ScreenToClient( &pt.x, &pt.y );
  wxHitTest ht = this->HitTest( pt );
  if( ht != wxHT_WINDOW_INSIDE ) {
    pt = this->PointFromPosition( this->GetCurrentPos() );
  }
  m_swx->DoContextMenu( Point( pt.x, pt.y ) );
}


void wxScintilla::OnMouseWheel( wxMouseEvent& evt ) {
  m_swx->DoMouseWheel( ScintillaWX::wxMOUSE_WHEEL_VERTICAL,
                       evt.GetWheelRotation(),
                       evt.GetWheelDelta(),
                       evt.GetLinesPerAction(),
                       1,
                       evt.ControlDown(),
                       evt.IsPageScroll() );
}


void wxScintilla::OnChar( wxKeyEvent& evt ) {
  bool ctrl = evt.ControlDown();
  bool alt  = evt.AltDown();
  bool skip = ( ( ctrl || alt ) && !( ctrl && alt ) );
  if( m_lastKeyDownConsumed && evt.GetUnicodeKey() > 255 ) {
    m_lastKeyDownConsumed = false;
  }
  if( !m_lastKeyDownConsumed && !skip ) {
    int key = evt.GetUnicodeKey();
    bool keyOk = true;
    if( key <= 127 ) {
      key = evt.GetKeyCode();
      keyOk = ( key <= 127 );
    }
    if( keyOk ) {
      m_swx->DoAddChar( key );
      return;
    }
  }
  evt.Skip();
}


void wxScintilla::OnKeyDown( wxKeyEvent& evt ) {
  int processed = m_swx->DoKeyDown( evt, &m_lastKeyDownConsumed );
  if( !processed && !m_lastKeyDownConsumed ) {
    evt.Skip();
  }
  if( evt.GetKeyCode() == WXK_TAB ) {
    NotifyTab();
  } else if( evt.GetKeyCode() == WXK_ESCAPE ) {
    NotifyEsc();
  }
}


void wxScintilla::OnLoseFocus( wxFocusEvent& evt ) {
  m_swx->DoLoseFocus();
  evt.Skip();
}


void wxScintilla::OnGainFocus( wxFocusEvent& evt ) {
  m_swx->DoGainFocus();
  evt.Skip();
}


void wxScintilla::OnSysColourChanged( wxSysColourChangedEvent& ( evt ) ) {
  m_swx->DoSysColourChange();
}


void wxScintilla::OnEraseBackground( wxEraseEvent& ( evt ) ) {
}



void wxScintilla::OnMenu( wxCommandEvent& evt ) {
  m_swx->DoCommand( evt.GetId() );
}


void wxScintilla::OnListBox( wxCommandEvent& ( evt ) ) {
  m_swx->DoOnListBox();
}


void wxScintilla::OnIdle( wxIdleEvent& evt ) {
  m_swx->DoOnIdle( evt );
}



void wxScintilla::OnTimer( wxTimerEvent& evt ) {
  m_swx->DoOnTimer( evt );
}



wxSize wxScintilla::DoGetBestSize() const {
  return wxSize( 600, 440 );
}





void wxScintilla::NotifyFocus( bool focus ) {
  wxScintillaEvent evt( focus ? wxEVT_SCI_SETFOCUS : wxEVT_SCI_KILLFOCUS, GetId() );
  evt.SetEventObject( this );
  GetEventHandler()->ProcessEvent( evt );
}

void wxScintilla::NotifyTab() {
  wxScintillaEvent evt( wxEVT_SCI_TAB, GetId() );
  evt.SetEventObject( this );
  GetEventHandler()->ProcessEvent( evt );
}

void wxScintilla::NotifyEsc() {
  wxScintillaEvent evt( wxEVT_SCI_ESC, GetId() );
  evt.SetEventObject( this );
  GetEventHandler()->ProcessEvent( evt );
}


void wxScintilla::NotifyChange() {
  wxScintillaEvent evt( wxEVT_SCI_CHANGE, GetId() );
  evt.SetEventObject( this );
  GetEventHandler()->ProcessEvent( evt );
}


static void SetEventText( wxScintillaEvent& evt, const char* text, size_t length ) {
  if( !text ) {
    return;
  }
  evt.SetString( sci2wx( text, length ) );
}


void wxScintilla::NotifyParent( SCNotification* _scn ) {
  SCNotification& scn = *_scn;
  wxScintillaEvent evt( 0, GetId() );
  evt.SetEventObject( this );
  evt.SetPosition( scn.position );
  evt.SetKey( scn.ch );
  evt.SetModifiers( scn.modifiers );
  switch( scn.nmhdr.code ) {
    case SCN_STYLENEEDED:
      evt.SetEventType( wxEVT_SCI_STYLENEEDED );
      break;
    case SCN_CHARADDED:
      evt.SetEventType( wxEVT_SCI_CHARADDED );
      break;
    case SCN_SAVEPOINTREACHED:
      evt.SetEventType( wxEVT_SCI_SAVEPOINTREACHED );
      break;
    case SCN_SAVEPOINTLEFT:
      evt.SetEventType( wxEVT_SCI_SAVEPOINTLEFT );
      break;
    case SCN_MODIFYATTEMPTRO:
      evt.SetEventType( wxEVT_SCI_ROMODIFYATTEMPT );
      break;
    case SCN_KEY:
      evt.SetEventType( wxEVT_SCI_KEY );
      break;
    case SCN_DOUBLECLICK:
      evt.SetEventType( wxEVT_SCI_DOUBLECLICK );
      evt.SetLine( scn.line );
      break;
    case SCN_UPDATEUI:
      evt.SetEventType( wxEVT_SCI_UPDATEUI );
      evt.SetUpdated( scn.updated );
      break;
    case SCN_MODIFIED:
      evt.SetEventType( wxEVT_SCI_MODIFIED );
      evt.SetModificationType( scn.modificationType );
      SetEventText( evt, scn.text, scn.length );
      evt.SetLength( scn.length );
      evt.SetLinesAdded( scn.linesAdded );
      evt.SetLine( scn.line );
      evt.SetFoldLevelNow( scn.foldLevelNow );
      evt.SetFoldLevelPrev( scn.foldLevelPrev );
      evt.SetToken( scn.token );
      evt.SetAnnotationLinesAdded( scn.annotationLinesAdded );
      break;
    case SCN_MACRORECORD:
      evt.SetEventType( wxEVT_SCI_MACRORECORD );
      evt.SetMessage( scn.message );
      evt.SetWParam( scn.wParam );
      evt.SetLParam( scn.lParam );
      break;
    case SCN_MARGINCLICK:
      evt.SetEventType( wxEVT_SCI_MARGINCLICK );
      evt.SetMargin( scn.margin );
      break;
    case SCN_NEEDSHOWN:
      evt.SetEventType( wxEVT_SCI_NEEDSHOWN );
      evt.SetLength( scn.length );
      break;
    case SCN_PAINTED:
      evt.SetEventType( wxEVT_SCI_PAINTED );
      break;
    case SCN_AUTOCSELECTION:
      evt.SetEventType( wxEVT_SCI_AUTOCOMP_SELECTION );
      evt.SetListType( scn.listType );
      SetEventText( evt, scn.text, strlen( scn.text ) );
      evt.SetPosition( scn.lParam );
      break;
    case SCN_USERLISTSELECTION:
      evt.SetEventType( wxEVT_SCI_USERLISTSELECTION );
      evt.SetListType( scn.listType );
      SetEventText( evt, scn.text, strlen( scn.text ) );
      evt.SetPosition( scn.lParam );
      break;
    case SCN_URIDROPPED:
      evt.SetEventType( wxEVT_SCI_URIDROPPED );
      SetEventText( evt, scn.text, strlen( scn.text ) );
      break;
    case SCN_DWELLSTART:
      evt.SetEventType( wxEVT_SCI_DWELLSTART );
      evt.SetX( scn.x );
      evt.SetY( scn.y );
      break;
    case SCN_DWELLEND:
      evt.SetEventType( wxEVT_SCI_DWELLEND );
      evt.SetX( scn.x );
      evt.SetY( scn.y );
      break;
    case SCN_ZOOM:
      evt.SetEventType( wxEVT_SCI_ZOOM );
      break;
    case SCN_HOTSPOTCLICK:
      evt.SetEventType( wxEVT_SCI_HOTSPOT_CLICK );
      break;
    case SCN_HOTSPOTDOUBLECLICK:
      evt.SetEventType( wxEVT_SCI_HOTSPOT_DCLICK );
      break;
    case SCN_CALLTIPCLICK:
      evt.SetEventType( wxEVT_SCI_CALLTIP_CLICK );
      break;
    case SCN_INDICATORCLICK:
      evt.SetEventType( wxEVT_SCI_INDICATOR_CLICK );
      break;
    case SCN_INDICATORRELEASE:
      evt.SetEventType( wxEVT_SCI_INDICATOR_RELEASE );
      break;
    case SCN_AUTOCCANCELLED:
      evt.SetEventType( wxEVT_SCI_AUTOCOMP_CANCELLED );
      break;
    case SCN_AUTOCCHARDELETED:
      evt.SetEventType( wxEVT_SCI_AUTOCOMP_CHAR_DELETED );
      break;
    case SCN_HOTSPOTRELEASECLICK:
      evt.SetEventType( wxEVT_SCI_HOTSPOT_RELEASE_CLICK );
      break;
    default:
      return;
  }
  GetEventHandler()->ProcessEvent( evt );
}

wxScintillaEvent::wxScintillaEvent( wxEventType commandType, int id )
  : wxCommandEvent( commandType, id ) {
  m_position = 0;
  m_key = 0;
  m_modifiers = 0;
  m_modificationType = 0;
  m_length = 0;
  m_linesAdded = 0;
  m_line = 0;
  m_foldLevelNow = 0;
  m_foldLevelPrev = 0;
  m_margin = 0;
  m_message = 0;
  m_wParam = 0;
  m_lParam = 0;
  m_listType = 0;
  m_x = 0;
  m_y = 0;
  m_token = 0;
  m_annotationLinesAdded = 0;
  m_updated = 0;
  #if wxUSE_DRAG_AND_DROP
  m_dragFlags = wxDrag_CopyOnly;
  m_dragResult = wxDragNone;
  #endif
}

bool wxScintillaEvent::GetShift() const { return ( m_modifiers & SCI_SHIFT ) != 0; }
bool wxScintillaEvent::GetControl() const { return ( m_modifiers & SCI_CTRL ) != 0; }
bool wxScintillaEvent::GetAlt() const { return ( m_modifiers & SCI_ALT ) != 0; }


wxScintillaEvent::wxScintillaEvent( const wxScintillaEvent& event ):
  wxCommandEvent( event ) {
  m_position = event.m_position;
  m_key = event.m_key;
  m_modifiers = event.m_modifiers;
  m_modificationType = event.m_modificationType;
  m_length = event.m_length;
  m_linesAdded = event.m_linesAdded;
  m_line = event.m_line;
  m_foldLevelNow =  event.m_foldLevelNow;
  m_foldLevelPrev = event.m_foldLevelPrev;
  m_margin = event.m_margin;
  m_message = event.m_message;
  m_wParam = event.m_wParam;
  m_lParam = event.m_lParam;
  m_listType = event.m_listType;
  m_x = event.m_x;
  m_y = event.m_y;
  m_token = event.m_token;
  m_annotationLinesAdded = event.m_annotationLinesAdded;
  m_updated = event.m_updated;
  #if wxUSE_DRAG_AND_DROP
  m_dragFlags = event.m_dragFlags;
  m_dragResult = event.m_dragResult;
  #endif
}
